Why c# datagridview returns double records?

  • Thread starter Thread starter Hungry_Minder
  • Start date Start date
H

Hungry_Minder

Guest
Hi,

I have a datagridview that I need to populate data from sql server.Here is the code.

using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Customers", con))
{
cmd.CommandType = CommandType.Text;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);

//Set AutoGenerateColumns False
gfDataGridView1.AutoGenerateColumns = true;

//Set Columns Count
gfDataGridView1.ColumnCount = 87;



gfDataGridView1.DataSource = dt;

}
}
}
}

This code returns me 87 columns (first 87) with totally empty and 87 columns with real data from database.How can I avoid these 87 empty columns?

604700



Thanks

Continue reading...
 
Back
Top