this.dataGrid1.DataSource=dset.Tables["aa"].DefaultView;
this.dataGrid1.DataBind();
this.dataGrid1.DataBind();
解决方案 »
- WPF如何用代码控制ListView滚动?
- 在线等,小问题,请指教!
- 类B的实例b是类A的成员,那么在类B中如何引用类A的成员?
- 使用C#进行数据库开发的一个问题
- 急!在线等。关于在C#中调用非托管.exe程序的问题?
- 调试运行c#项目的时候遇到错误Task failed because "AL.exe" was not found
- 更改已经生成的exe的图标
- 未将对象引用设置到对像的实例
- 请问VS2012跑起来的WEB API如何在其他机器访问
- 刚学C#,马上要写个项目,B/S结构的,但是发现自己概念不清楚
- 智能设备连SQL server
- 如何从SqlDataReader中获取bit型数据的值
不过如果是WinForm的话,就没有 this.dataGrid1.DataBind();
这一句啦
同意楼上的观点
否则dataGrid1不能显示表aa.
仅供参考。
this.dataGrid1.DataSource=dset;这样就可以了,不必对datatable取名字——如果你只有一个datatable的话。再有了,如果你只是单纯的绑定到datagrid,直接设置他的datasource为一个command返回的reader就可以了。
private void button2_Click(object sender, System.EventArgs e)
{
string source="server=ks052;uid=hdh;pwd=huang;database=hdh";
string strsql="select * from tabx"; SqlDataAdapter da=new SqlDataAdapter(strsql,source);
DataSet ds=new DataSet();
da.Fill(ds,"tab");
dataGrid1.SetDataBinding(ds,"tab");}
不过this.dataGrid1.DataSource=dset//是不能直接看到数据的
this.dataGrid1.DataSource=dset.Table[0].DefaultView;//某长表的默认视图