i use this code
private void button1_Click(object sender, EventArgs e)
{
displaygrid.DataSource = null;
cmd.CommandText= "selectregid,studname,regno,classname,dob,sex,parent,houseno,place1,place2,city,phono,mobno,office,offplace1,offplace2,offcity,offpho,offmob,fax,nationalty,busno from registration r inner join class c on r.classid = c.classid inner join bus b on r.busid = b.busid where r.Studname='" + textBox1.Text + "'";
da.SelectCommand = cmd;
da.Fill(ds, "name");
DataTable dt1 = ds.Tables["name"];
//dt.Clear();
displaygrid.DataSource = dt1;
}
Sahil JaniPosted Apr 7, 2011, 4:30 AM
Hi Shyja,
This code is written for MS-Access Database. This code will might help you.
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection MyConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\*.mdb");
string str2;
str2 = "SELECT * FROM *";
OleDbDataAdapter da = new OleDbDataAdapter(str2, MyConnection);
MyConnection.Open();
DataSet ds1 = new DataSet();
OleDbCommandBuilder commandBuilder = new OleDbCommandBuilder(da);
da.Fill(ds1, "others");
BindingSource bsource = new BindingSource();
bsource.DataSource = ds1.Tables["others"];
dataGridView1.DataSource = bsource;
}
If this code will satisfy your given need in the question then marked this post as "ACCEPTED ANSWER"
Ankit NandekarPosted Apr 7, 2011, 2:09 AM
displaygrid.datasource=null;
displaygrid.databind();
after giving datasource =null you should bind it.