如何在预定义列名的位置添加数据集值C# [英] How to add dataset values where column names are predefined C#
本文介绍了如何在预定义列名的位置添加数据集值C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据集,其数据表具有预定义列,即
Id,名称,DOB,名称,移动,邮件,工资
如何用特定记录中的特定列填充数据表
I am having a dataset with a data table having predefined column namely
Id,Name,DOB,Designation,Mobile,Mail,Salary
How to fill the data table with particular columns on particular record
推荐答案
我认为我稍微误解了这个问题。
如果你想在数据表中添加一行,你可以这样做。
I think I misunderstood the question a little.
If you want to add a row to a data table you can do like this.
DataSet ds; // your predefined dataset
DataTable dt = ds.Tables[0];
or
DataTable dt = ds.Tables["MyTable"];
dt.Rows.Add(1, "Harry Hacker", "DOB", "Programmer", "123456789", "harry.hacker@codeville.com", "
1);
或
DataRow dr = dt.Rows.New();
dr [ Id] = 1 跨度>;
dr [ 名称] = 哈里黑客;
dr [ DOB] = 这意味着什么;
dr [ 名称] = 程序员;
dr [ Mobile] = 123456789;
dr [ Mail] = harry.hacker@codeville.com;
dr [ 薪水] =
1"); or DataRow dr = dt.Rows.New(); dr["Id"] = 1; dr["Name"] = "Harry Hacker"; dr["DOB"] = "What ever this means"; dr["Designation"] = "Programmer"; dr["Mobile"] = "123456789"; dr["Mail"] = "harry.hacker@codeville.com"; dr["Salary"] = "
1;
dt.Rows.Add(dr);
1"; dt.Rows.Add(dr);
如果您有 DataGridView
调用 dgView
你可以添加 DataSet
作为数据源。
dgView.DataSource = ds;
dgView.DataMember =MyTable;
我的第一个答案,可能不是目标。
If you have a DataGridView
called dgView
you can add the DataSet
as the data source.
dgView.DataSource = ds;
dgView.DataMember = "MyTable";
My first answer, not maybe on target.
foreach (DataRow dr in dt.Rows)
{
dr["Id"] = some_value;
dr["Name"] = some_other_value;
etc.
}
这篇关于如何在预定义列名的位置添加数据集值C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文