向exsit数据集添加新cloumn [英] Add new cloumn to exsit dataset
本文介绍了向exsit数据集添加新cloumn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家每个
i都有 我的网站其中我可以在中循环和获取我需要的所有文件将新列添加到现有数据设置 此我的代码
string sourceDir = Server.MapPath( 〜/ folder1中/文件夹2 /跨度>);
string [] fileEntries = Directory.GetFiles(sourceDir).OrderBy(filename = > 文件名).ToArray();
foreach (字符串 fileName in fileEntries)
{
string x = < img src = \ + Path.GetFileName(fileName)+ \/>< br />;
}
此数据 set 已经拥有我需要的数据使用 之前的代码
新列添加到同一数据集中的相同数据集code-keyword> if (ds.Tables.Count > 0 )
{
// 做点什么
}
如何做到
我尝试过:
string sourceDir = Server.MapPath(〜/ folder1 / folder2 /);
string [] fileEntries = Directory.GetFiles(sourceDir).OrderBy(filename = > filename)。ToArray();
foreach(fileEntries中的字符串fileName)
{
string x =< img src = \+ Path.GetFileName(fileName)+\/>
;
}
if (ds.Ta bles.Count> 0)
{
//做点什么
}
怎么样可以完成
解决方案
因为DataSet是DataTables的集合,所以你想要将列添加到DataTable 1,
DataTable dt = ds.Tables [0];
dt .Columns.Add(ColumnName,typeof(datatype));
然后,您可以通过迭代行并访问特定列来设置值。 br $>
谢谢,
Raghuveer
System.Data.DataColumn newColumn = new System.Data.DataColumn (Foo,typeof(System.String));
newColumn.DefaultValue =Your Colume DefaultValue
table.Columns.Add(newColumn);< /预>
hi every body
i have folder in my website where i can loop in it and get all files ordered i need to add anew column to an exist data set this my code
string sourceDir = Server.MapPath("~/folder1/folder2/");
string[] fileEntries = Directory.GetFiles(sourceDir).OrderBy(filename => filename).ToArray();
foreach (string fileName in fileEntries)
{
string x = "<img src=\"" + Path.GetFileName(fileName) + "\" /><br />";
}
this data set already have data i need to add anew colum to the same dataset with the image path from previous code
if (ds.Tables.Count > 0)
{
// do something
}
how it can be done
What I have tried:
string sourceDir = Server.MapPath("~/folder1/folder2/");
string[] fileEntries = Directory.GetFiles(sourceDir).OrderBy(filename => filename).ToArray();
foreach (string fileName in fileEntries)
{
string x = "<img src=\"" + Path.GetFileName(fileName) + "\" />
";
}
if (ds.Tables.Count > 0)
{
// do something
}
how it can be done
解决方案
Hi,
As the DataSet is the collection of DataTables, say you want to add column to DataTable 1,
DataTable dt = ds.Tables[0];
dt.Columns.Add("ColumnName",typeof(datatype));
Then, you can set the values by iterating through the Rows and accessing the specific column.
Thanks,
Raghuveer
System.Data.DataColumn newColumn = new System.Data.DataColumn("Foo",typeof(System.String));
newColumn.DefaultValue = "Your Colume DefaultValue"
table.Columns.Add(newColumn);</pre>
这篇关于向exsit数据集添加新cloumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文