DataGridView不显示数据 [英] DataGridView not showing data

查看:640
本文介绍了DataGridView不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows窗体中有一个dataGrid视图,现在我想以编程方式绑定它.我写这段代码:

I have a dataGrid view in my windows form and now i want bind it programatically. i write this code:

string ConnString = "";
sqlConnection conn = new SqlConnection (ConnString);
string sql = "";
sqlDataAdapter da = new SqlDataAdapter(sql,conn);
conn.open()l
dataset ds = new dataset();
da.fill(ds);
conn.close();
datagridview1.DataSource = ds;


我的代码正确,并且ds hase 1条记录和正确填充,但是我的网格不显示任何记录.你知道为什么吗?我缺少任何内容吗?


My code is right and ds hase 1 record and fill right but my grid dont show any record. do you know why? Am I missing anything?

推荐答案

是的,您缺少一行代码.您忘记了将数据绑定到网格.您只需为网格设置数据.您需要触发它的bind方法.

放在末尾:
Yes, you are missing one line of code. You forgot to bind the data to the grid. You just set the data for grid. You need to trigger it''s bind method.

Put this at the end:
datagridview1.Databind();


应该可以的.

更新:
对于Winforms: Datagrid示例 [


This should do.

UPDATE:
For Winforms: Datagrid sample[^]


之后:
datagrdview1.DataSource = ds;

添加:
datagridview1.DataBind();
after:
datagrdview1.DataSource = ds;

add:
datagridview1.DataBind();


,但它是Windows窗体,没有databind()

什么是databind()的插入对象?
but its windows form and has no databind()

what is insted of databind()?


这篇关于DataGridView不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆