Click here to Skip to main content
15,919,774 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
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
Posted
Updated 3-Apr-16 19:13pm
Comments
RickZeeland 3-Apr-16 9:51am    
Here is an example: http://www.codeproject.com/Questions/736935/How-to-Add-New-column-to-dataset

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
 
Share this answer
 
System.Data.DataColumn newColumn = new System.Data.DataColumn("Foo",typeof(System.String));
newColumn.DefaultValue = "Your Colume DefaultValue"
table.Columns.Add(newColumn);</pre>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900