Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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. I have the following code so far:
C#
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();
            }
        }
Posted
Updated 26-Sep-14 7:22am
v2

1 solution

There are several ways to add to a ListView control. The important thing to know is to add to the Items collection.

See http://stackoverflow.com/questions/9951704/add-item-to-listview-control[^] for a few different methods.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900