Need help: fill dataset

T

Tee

Hi,

I need some help about filling dataset, I am not sure how to describe it, so
I give the example here.

da = new OleDbDataAdapter("SELECT * FROM Path WHERE PathID=1", cnn);

da.Fill(DataSet, "Path");



this is the code of current DataAdapter filling up a DataSet.

What I wanted to do now is fill the DataSet with specified data from Code,
not from DataAdapter.

Is this possible? if yes, how to do it?



Thanks,
Tee
 
G

Grzegorz Danowski

U¿ytkownik "Tee said:
Hi,

I need some help about filling dataset, I am not sure how to describe it,
so
I give the example here.

da = new OleDbDataAdapter("SELECT * FROM Path WHERE PathID=1", cnn);

da.Fill(DataSet, "Path");



this is the code of current DataAdapter filling up a DataSet.

What I wanted to do now is fill the DataSet with specified data from Code,
not from DataAdapter.

Is this possible? if yes, how to do it?

For example:

DataRow dr = DataSet["Path"].NewRow();
dr[0] = 34;// value of 34 to first field
dr["AnotherColumn"] = "A string";
....
etc.

DataSet["Path"].Rows.Add(dr);

I hope it helps.
Grzegorz
 
J

Jim Hughes

Something along these lines should work. Replace field1 with your field
names.

Use the NewRow() method of the Dataset DataTable, populate the data and Add
it to the DataTable Rows colleciton.

System.Data.DataSet DataSet1 = new System.Data.DataSet();

System.Data.DataTable dt = new System.Data.DataTable();

System.Data.DataColumn dc = new System.Data.DataColumn("Field1",
typeof(System.String));

dt.Columns.Add(dc);

DataSet1.Tables.Add(dt);

System.Data.DataRow dr = dt.NewRow();

dr["Field1"] = "your data1";

dt.Rows.Add(dr);
 

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