Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Why DataBinding doesn't work on second time around?

$
0
0

Hi Guys

My code below search for a record in excel based on a textbox text and bind it to a datagrid. but if I tried searching for the same value and bind it again I got error " DataBinding cannot find a row in the list that is suitable for all bindings." any idea how to reset the binding ? I tries formattingEnables set to true it didn't work. thank you

 OleDbConnection connExcel = new OleDbConnection(_econnect);
            cmdExcel.Connection = connExcel;
            connExcel.Open();
            DataTable dt;
            DataSet ds = new DataSet();
            dt = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
            OleDbDataAdapter da = new OleDbDataAdapter();
            string sheetname = "BadgeID$";
            cmdExcel.CommandText = "select ID, Name, Dept from [" + sheetname + "] where ID in (" + sss +")";
            da.SelectCommand = cmdExcel;
            da.Fill(ds);
            connExcel.Close();
           bsdata .DataSource = ds.Tables [0]; //error here
           Invoke(new MethodInvoker(() => textBox1.DataBindings.Add("Text", bsdata, "Name")));
           Invoke(new MethodInvoker(() => textBox2.DataBindings.Add("Text", bsdata, "Dept")));



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>