Add a column in dataset

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
 
C

Cor Ligthert [MVP]

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
 
W

W.G. Ryan - MVP

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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top