通过DataSet将数据添加到DataGrid View? [英] add data to DataGrid View through DataSet?

查看:181
本文介绍了通过DataSet将数据添加到DataGrid View?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datagridview绑定到数据集

I have a datagridview that is bound to a dataset

我定义了表和列,我如何可以编程插入数据?

I defined the table and the columns, how I can programmaticlly insert data to it?

我这样做
http://msdn.microsoft.com/en-us/library/5ycd1034%28VS.71%29.aspx

但它没有显示DataGridView中的数据!!!

but it did not show the data in my DataGridView !!!

推荐答案

示例

SqlDataAdapter da = new SqlDataAdapter(quryString, con);
DataSet ds = new DataSet();
da.Fill(ds, "Emp");

//dataGridView1.DataSource = ds.Tables["Emp"];
dataGridView1.Columns.Add("EmpID", "ID");
dataGridView1.Columns.Add("FirstName", "FirstName");
dataGridView1.Columns.Add("LastName", "LastName");
int row = ds.Tables["Emp"].Rows.Count - 1;

for (int r = 0; r<= row; r++)
{
dataGridView1.Rows.Add();
dataGridView1.Rows[r].Cells[0].Value = ds.Tables["Emp"].Rows[r].ItemArray[0];
dataGridView1.Rows[r].Cells[1].Value = ds.Tables["Emp"].Rows[r].ItemArray[1];
dataGridView1.Rows[r].Cells[2].Value = ds.Tables["Emp"].Rows[r].ItemArray[2];

}

这篇关于通过DataSet将数据添加到DataGrid View?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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