Click here to Skip to main content
15,911,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
With the following code I wanted to add a column dynamically but I get this error at line
'ds21.Columns.Add(theCol);'


Error 13 'System.Data.DataSet' does not contain a definition for 'Columns' and no extension method 'Columns' accepting a first argument of type 'System.Data.DataSet' could be found (are you missing a using directive or an assembly reference?)

My code:

DataSet ds21 = new DataSet("productname");
DataColumn theCol = new DataColumn("Groups", typeof(string));
ds21.Columns.Add(theCol);
da2.Fill(ds21, "productname");

How to rectify this.
Posted

DataSets don't have Columns; DataTables do.

Additionally, I don't think that will work even if you try to do it with a DataTable. You might consider adding the column to the query you are using to get the data.
 
Share this answer
 
Isnt a DataSet a collection of DataTables ?

I know you can do this :-

C#
DataTable dt21 = new DataTable("productname");
DataColumn theCol = new DataColumn("Groups", typeof(string));
dt21.Columns.Add(theCol);
da2.Fill(dt21, "productname");


and then you'd likely do this :-

C#
DataSet set = new DataSet("productmaster");
	set.Tables.Add(dt21);


for example

....

'g'
 
Share this answer
 
Try this..


C#
DataTable ds21 = new DataTable("productname");
    da2.Fill(ds21);
    DataColumn theCol = new DataColumn("Groups", typeof(string));
    ds21.Columns.Add(theCol);
 
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