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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manoj BhoirRank #599 · 4K reputationPosted May 8, 2015, 2:03 AM EDT
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();
Dipankar BiswasRank #992 · 2K reputationPosted May 8, 2015, 12:53 AM EDT
http://stackoverflow.com/questions/14340567/c-datagridview-shows-only-one-row
Carlos kambuiRank #2,642 · 528 reputationPosted May 8, 2015, 2:26 AM EDT
Carlos kambuiRank #2,642 · 528 reputationPosted May 8, 2015, 2:54 AM EDT
var adaptor = new SqlDataAdapter ();
adaptor.SelectCommand = cmd;
Manoj BhoirRank #599 · 4K reputationPosted May 8, 2015, 2:57 AM EDT