error in combobox databinding
-
i m trying to fill the combo box with the data from the access database but i m getting the error "Object reference not set to an instance of an object." i m writing the following code for the purpose
con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=practicedatabase.accdb");
con.Open();
string qry = "Select * from cat_table";
dadapter = new OleDbDataAdapter(qry, con);
dset = new DataSet();
DataTable dt = new DataTable("cat_table");
dadapter.Fill(dt);
this.comboBox1.DataSource = dt;
this.comboBox1.DisplayMember = dt.Columns[1].ColumnName; -
i m trying to fill the combo box with the data from the access database but i m getting the error "Object reference not set to an instance of an object." i m writing the following code for the purpose
con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=practicedatabase.accdb");
con.Open();
string qry = "Select * from cat_table";
dadapter = new OleDbDataAdapter(qry, con);
dset = new DataSet();
DataTable dt = new DataTable("cat_table");
dadapter.Fill(dt);
this.comboBox1.DataSource = dt;
this.comboBox1.DisplayMember = dt.Columns[1].ColumnName;Trace & check the value dt.Columns[1].ColumnName at the following line
this.comboBox1.DisplayMember = dt.Columns[1].ColumnName;
Sample Code
comboBox1.DataSource = dt;//Datasource to be bind (Ex. cat_table data)
comboBox1.DisplayMember = "Cat_Name";//The Column to be displayed (Ex. Cat_Name)thatraja
-
Trace & check the value dt.Columns[1].ColumnName at the following line
this.comboBox1.DisplayMember = dt.Columns[1].ColumnName;
Sample Code
comboBox1.DataSource = dt;//Datasource to be bind (Ex. cat_table data)
comboBox1.DisplayMember = "Cat_Name";//The Column to be displayed (Ex. Cat_Name)thatraja