how to display more than one record on datagridview
i have a sql database whenever i load table with more than one record it does not display it only display if table has only record ,how an i solve please using c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Manoj BhoirPosted May 8, 2015, 6:03 AM
Create a method for grabbing the data like this :
public DataTable GetDataTable()
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection (@"YourConnectionString"))
{
using (SqlCommand cmd = new SqlCommand (query, con))
{
var adaptor = new SqlDataAdapter ();
adaptor.SelectCommand = cmd;
con.Open();
adaptor.Fill(dt);
return dt;
}
}
}
Then You can reference it with your DataGrid :
DatagridView1.DataSource = GetDataTable();
Manoj BhoirPosted May 8, 2015, 6:57 AM
Carlos kambuiPosted May 8, 2015, 6:54 AM
var adaptor = new SqlDataAdapter ();
adaptor.SelectCommand = cmd;
Carlos kambuiPosted May 8, 2015, 6:26 AM
Dipankar BiswasPosted May 8, 2015, 4:53 AM
http://stackoverflow.com/questions/14340567/c-datagridview-shows-only-one-row