Reputation: 77
I'm trying to retrieve data from database and display it in a listbox. I've got the following code and when I run it, it gives no error or something but no data is showing up in the listbox.
connection.Open();
DataTable dt = new DataTable();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "select * from Appointments where PersonID = '" + textBox4.Text + "'";
OleDbDataReader reader = command.ExecuteReader();
dt.Load(reader);
foreach (DataRow Dr in dt.Rows)
{
listBox1.Items.Add(Dr["PersonID"].ToString());
}
connection.Close();
Upvotes: 1
Views: 86
Reputation: 5380
You don't show your connection string, but it sounds like one of the old gotchas when working with file based databases (Access as it seems you're using) from within Visual Studio.
If your MDB file is part of the project, and its "Action" is set to "Copy always", then every time you run your application, the MDB file in the BIN folder will get overwritten by the one in your source folder, thus overwriting any changes you made in the last run.
Please verify that this is not the case as it's one common source of problem.
Cheers
Upvotes: 2