Add a column in dataset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear all,

I get a result from the sql server and return a dataset
after i get the dataset, i want to add a column to the dataset
the column is boolean and all rows are true, how to do that
 
Joe,

You never can add a column to a dataset. A dataset is a wrapper which hold
relations and datatables.

You can add a column to a datatable. In visual basic by instance as

ds.tables(0).columns.Add("myColumn",gettype(system.boolean))

I hope this hellps,

Cor
 
Joe, you just need to instantiate a new DataColumn of type Boolean and then
set its DefaultValue property to true and then add it to the table's Columns
collection. The code below essentially illustrates each item for you:

DataTable dt = new DataTable("DemoTable");

//DataAdapter.Fill(dt); //Call your Fill method here and get a dataset or
datatable back.

DataColumn BoolColumn = new DataColumn("BoolColumn",
typeof(System.Boolean));

BoolColumn.DefaultValue = true;

dt.Columns.Add(BoolColumn);
 
Back
Top