hi
i have a combo box which i populate with all tables from northwind database
and when the user selects an item from the combo, i want to populate the
datagrid with data from that table.
private void FillComboBox()
{
DataSet allTablesDataSet = new DataSet("AllTables");
string sqlString;
this.tableComboBox.Items.Clear();
sqlString = "Select * from sysobjects where type ='u'";
this.sqlDataAdapter = new SqlDataAdapter();
this.sqlDataAdapter.SelectCommand = new SqlCommand(sqlString,
this.sqlConnection);
this.sqlDataAdapter.Fill(allTablesDataSet,"AllTabl es");
this.tableComboBox.DataSource = allTablesDataSet.Tables[0];
this.tableComboBox.DisplayMember = "name";
this.tableComboBox.ValueMember = "name";
}
private void OnTableComboBoxSelectedIndexChanged(object sender,
System.EventArgs e)
{
if(this.tableComboBox.SelectedIndex == -1)
return;
this.tableDataSet = new DataSet();
this.sqlDataAdapter.SelectCommand = new SqlCommand("Select * from [" +
this.tableComboBox.SelectedValue + "]" ,this.sqlConnection);
this.sqlDataAdapter.Fill(this.tableDataSet, "Table");
this.dataGrid1.DataSource = this.tableDataSet;
this.dataGrid1.DataMember = "Table";
}
however the first time when the program is run i get the foll error. how do
i resolve that?
thnx
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred
in system.data.dll
Additional information: System error.
on this line
this.sqlDataAdapter.Fill(this.tableDataSet, "Table");