Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ,everyone
Data display in datagridview and not display in two text boxes in the same time ??
and this is my code in button:

C#
da.SelectCommand = new SqlCommand("select * from tblcontacts ",cs);
           ds.Clear();
           da.Fill(ds);
           dataGridView1.DataSource = ds.Tables[0];
           DataTable dt = new DataTable();
           dt.Columns.Add("firstname", typeof(string));
           dt.Columns.Add("lastname", typeof(string));

           tblnamesbs.DataSource = dt;
           this.textBox1.DataBindings.Add("Text", this.tblnamesbs, "firstname", true);
           this.textBox2.DataBindings.Add("Text", this.tblnamesbs, "lastname", true);
Posted
Updated 6-Jan-14 14:06pm
v3

The datatable dt is not a object reference from ds.Tables[0].
In your code, you created dt as a new datatable, and created the two columns, but the table is never filled.
 
Share this answer
 
Comments
mhassan083 6-Jan-14 15:12pm    
how can i filled?
sample:
C#
OleDbDataAdapter dAdapter = new OleDbDataAdapter("select * from oui_table", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=bd.mdb");
dAdapter.Fill(ds, "t1");

this.dataGridView1.DataSource = ds.Tables["t1"];

this.textBox1.DataBindings.Add(new Binding("text", ds.Tables["t1"], "id_oui"));
 
Share this answer
 
you are trying to assign a empty datatable to bindingsource.

try like this.
C#
tblnamesbs.DataSource = dt;
tblnamesbs.DataSource = ds.Tables[0];
this.textBox1.DataBindings.Add("Text", this.tblnamesbs, "firstname", true);
this.textBox2.DataBindings.Add("Text", this.tblnamesbs, "lastname", true);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900