本文介绍了绑定网格中的错误:网格视图未绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void grid_view()
{
string s = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
string sel = "select * from TableName";
SqlConnection con = new SqlConnection(s);
SqlCommand cmd = new SqlCommand(sel, con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds;
dataGridView1.DataBind();
}
运行代码时出现此错误
"
``System.Windows.Forms.DataGridView''不包含``DataBind''的定义,并且没有接受类型为``System.Windows.Forms.DataGridView''的第一个参数的扩展方法``DataBind''找到(是否缺少using指令或程序集引用?)
"
i have this error when i run my code
"
''System.Windows.Forms.DataGridView'' does not contain a definition for ''DataBind'' and no extension method ''DataBind'' accepting a first argument of type ''System.Windows.Forms.DataGridView'' could be found (are you missing a using directive or an assembly reference?)
"
推荐答案
dataGridView1.DataSource = ds.Tables[0];
如果仍然看不到网格中的任何内容,请在代码中放置一个断点,并检查数据表中是否确实有行.
If you''re still not seeing anything in the grid, put a breakpoint in your code and check that there actually are rows in your datatable.
这篇关于绑定网格中的错误:网格视图未绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!