我有一个datagridview,我需要从sql server填充数据。这是代码。
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;
}
}
}
}
此代码返回87列(前87个),完全为空,87列包含来自数据库的真实数据。如何避免这87个空列?