我有一个datagridview绑定到一个数据集通过DataSet将数据添加到DataGrid视图?
我定义了表和列,我可以如何编程地向其插入数据?
我这样做 http://msdn.microsoft.com/en-us/library/5ycd1034%28VS.71%29.aspx
但它并没有在我的DataGridView显示的数据!
我有一个datagridview绑定到一个数据集通过DataSet将数据添加到DataGrid视图?
我定义了表和列,我可以如何编程地向其插入数据?
我这样做 http://msdn.microsoft.com/en-us/library/5ycd1034%28VS.71%29.aspx
但它并没有在我的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];
}
现在你需要将值分配到DataGridView
DataTable dt = new DataTable();
// Add rows to dt
datagridview.DataSource = dt;
它可以直接为界。
DataSet ds = new DataSet();
在C#
DataGridView.DataSource = ds.Tables["your Table index which you want to bind with datagridview"];
喜欢
DataGridView.DataSource = ds.Tables[0];
在VB
DataGridView.DataSource = ds.Tables("your Table index which you want to bind with datagridview")
像
DataGridView.DataSource = ds.Tables(0)
但datagridview的已经与数据集配置!可以吗? – 2010-08-13 10:13:40