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 allTablesDataSe t = new DataSet("AllTab les");
string sqlString;
this.tableCombo Box.Items.Clear ();
sqlString = "Select * from sysobjects where type ='u'";
this.sqlDataAda pter = new SqlDataAdapter( );
this.sqlDataAda pter.SelectComm and = new SqlCommand(sqlS tring,
this.sqlConnect ion);
this.sqlDataAda pter.Fill(allTa blesDataSet,"Al lTables");
this.tableCombo Box.DataSource = allTablesDataSe t.Tables[0];
this.tableCombo Box.DisplayMemb er = "name";
this.tableCombo Box.ValueMember = "name";
}
private void OnTableComboBox SelectedIndexCh anged(object sender,
System.EventArg s e)
{
if(this.tableCo mboBox.Selected Index == -1)
return;
this.tableDataS et = new DataSet();
this.sqlDataAda pter.SelectComm and = new SqlCommand("Sel ect * from [" +
this.tableCombo Box.SelectedVal ue + "]" ,this.sqlConnec tion);
this.sqlDataAda pter.Fill(this. tableDataSet, "Table");
this.dataGrid1. DataSource = this.tableDataS et;
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.Sq lClient.SqlExce ption' occurred
in system.data.dll
Additional information: System error.
on this line
this.sqlDataAda pter.Fill(this. tableDataSet, "Table");
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 allTablesDataSe t = new DataSet("AllTab les");
string sqlString;
this.tableCombo Box.Items.Clear ();
sqlString = "Select * from sysobjects where type ='u'";
this.sqlDataAda pter = new SqlDataAdapter( );
this.sqlDataAda pter.SelectComm and = new SqlCommand(sqlS tring,
this.sqlConnect ion);
this.sqlDataAda pter.Fill(allTa blesDataSet,"Al lTables");
this.tableCombo Box.DataSource = allTablesDataSe t.Tables[0];
this.tableCombo Box.DisplayMemb er = "name";
this.tableCombo Box.ValueMember = "name";
}
private void OnTableComboBox SelectedIndexCh anged(object sender,
System.EventArg s e)
{
if(this.tableCo mboBox.Selected Index == -1)
return;
this.tableDataS et = new DataSet();
this.sqlDataAda pter.SelectComm and = new SqlCommand("Sel ect * from [" +
this.tableCombo Box.SelectedVal ue + "]" ,this.sqlConnec tion);
this.sqlDataAda pter.Fill(this. tableDataSet, "Table");
this.dataGrid1. DataSource = this.tableDataS et;
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.Sq lClient.SqlExce ption' occurred
in system.data.dll
Additional information: System error.
on this line
this.sqlDataAda pter.Fill(this. tableDataSet, "Table");
Comment