0 Replies - 878 Views - Last Post: 29 September 2014 - 12:52 AM Rate Topic: -----

#1 courtz777   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-September 14

How do I display data from ms access in a listView control using sql q

Posted 29 September 2014 - 12:52 AM

I would like to display the data in my database in a list view control in microsoft visual web developer 2010, using C# and an ms access database. My users need to be able to select an option (to reserve a room).

The user selects an arrival date and a departure date from two text boxes and then presses the search button which displays all the available rooms in the listview control. I have the following code so far:

protected void searchBtn_Click(object sender, EventArgs e)
        {
            //when the search button is selected these controls become visible
            selectRoomLbl.Visible = true; 
            reserveBtn.Visible = true;
            ListView1.Visible = true;
 
            try
            {
                //creates a connection to the database
                dbConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" +
                    Request.PhysicalApplicationPath + "App_Data\\Mercure.accdb");
 
                dbConnection.Open();
 
                //query retrieves all available rooms for reservation
                string query = "SELECT * FROM RoomsDetails WHERE roomID NOT IN(";
                query += "SELECT roomID FROM ReservationDetails WHERE NOT(";
                query += "dateArrival < " + arrivalTxt.Text + "OR dateDeparture > " + departureTxt.Text + "))";
                query += "ORDER BY RoomsDetails.roomID";
 
                OleDbCommand cmd = dbConnection.CreateCommand();
                cmd.CommandText = query;
                OleDbDataReader dbReader = cmd.ExecuteReader();
 
                if (dbReader != null && dbReader.HasRows)
                {
                    while (dbReader.Read())
                    {
                        //I am not too sure how to display in the listview control                  
                    }
                }                 
            }
            finally
            {
                dbConnection.Close();
            }
        }


I have searched a lot on how to add data from ms access to a listview control, but most of the searches just come up with adding data to the control without a database. I have tried tried binding it to the datasource, but then i am not too sure how to just display the data i want...

I have also tried to use a gridview control... I was able to display the available rooms in the gridview control, but then wasn't too sure how to select a row (room option).

Is This A Good Question/Topic? 0
  • +

Page 1 of 1