J
JB
I am trying to bind a ListBox to a dataset and am having some troubles
getting it working right.
I have source something like so:
//query and store the data into the DataSet
SqlCommand command = new SqlCommand();
string numToSearchFor =
Properties.Settings.Default.NumProductsToSearch;
command.CommandText = "SELECT TOP " + numToSearchFor + "[Items] FROM
PriIMS_db.dbo.Product ORDER BY Items DESC";
command.Connection = myConnection;
SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = command;
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet,"Product");
//bind the data
listBoxVsnProducts.ValueMember = "Items";
listBoxVsnProducts.DisplayMember = "Items";
listBoxVsnProducts.DataSource = products.Tables[0];
However all i'm getting is a blank listbox at the end of it.
It has the right number of entries (determined by the value
'numToSearchFor') but they are all blank.
It's probably something nooby i'm doing at the binding stage, the
dataset itself is ok because I can do something like so:
foreach (DataRow dataRow in products.Tables[0].Rows)
//add item dataRow[0] into the listbox
and it works fine
getting it working right.
I have source something like so:
//query and store the data into the DataSet
SqlCommand command = new SqlCommand();
string numToSearchFor =
Properties.Settings.Default.NumProductsToSearch;
command.CommandText = "SELECT TOP " + numToSearchFor + "[Items] FROM
PriIMS_db.dbo.Product ORDER BY Items DESC";
command.Connection = myConnection;
SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = command;
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet,"Product");
//bind the data
listBoxVsnProducts.ValueMember = "Items";
listBoxVsnProducts.DisplayMember = "Items";
listBoxVsnProducts.DataSource = products.Tables[0];
However all i'm getting is a blank listbox at the end of it.
It has the right number of entries (determined by the value
'numToSearchFor') but they are all blank.
It's probably something nooby i'm doing at the binding stage, the
dataset itself is ok because I can do something like so:
foreach (DataRow dataRow in products.Tables[0].Rows)
//add item dataRow[0] into the listbox
and it works fine