Hi, I have a function for fetching data from a database via a dataset
public DataSet getDataSet(string query)
{
DataSet ds = new DataSet();
OleDbDataAdapter da1 = new OleDbDataAdapter(query, sybaseconn);
OleDbCommand cmd1 = new OleDbCommand(query, sybaseconn);
cmd1.CommandType = CommandType.StoredProcedure;
da1.SelectCommand = cmd1;
da1.Fill(ds, "tbl");
da1.Dispose();
da1 = null;
SybaseconnClose();
return ds;
}
This works fine. The selected columns are "Nr" and "Remark" I call this function in the next function. My datagridview will bound with the dataset.
private void LoadData()
{
dataGridView1.DataSource = null;
Application.DoEvents();
TTT3Dal awdal = new TTT3Dal();
DataSet dsAWIA = awdal.getDataSet("select_tbl");
awdal.dsTTT3 = dsAWIA;
dataGridView1.DataSource = dsAWIA.Tables["tbl"].DefaultView;
bindingSource1.DataMember = "tbl";
//dataGridView1.DataBindings.Add("Text", bindingSource1, "nr");
}
This works fine as well. In the form I call the last function and the bindingNavigator.
public Form1()
{
InitializeComponent();
LoadData();
bindingNavigator1.BindingSource = bindingSource1;
}
Works fine BUT if I uncomment this line
//dataGridView1.DataBindings.Add("Text", bindingSource1, "nr");
I get this error
Cannot bind to the property or column nr on the DataSource. Parameter name: dataMember
I tried to solve this by adding the line
dataGridView1.DataMember = "tbl";
But then I get the error
Child list for field tbl cannot be created.
Could someone please help me solve this and help me bind the datagridview to the bindingnavigator