Why Fill creates two datatables in dataset?

J

John Sutter

The first iteration in the loop in the code below creates two datatables.
This is unexpected as I am expecting one called Table0.
(The SqlDataAdapter uses a stored procedure which returns a single
resultset. dsDF is a variable of a dataset class which has an xsd file)

When I checked the tablename of the first table, it had the name of the
stored procedure instead of "Table0" which went to the second table
instead. Is this normal behavior? I might be missing a simple fact.
(rowcount for first table is 0)

code snippet:

for (int i =0; i < 6; i++) {
this.sqlDataAdapter1.Fill(dsDF, "Table" + i.ToString());
tablename = dsDF.Tables.TableName; // for debugging purposes
rowscount = dsDF.Tables.Rows.Count; // for debugging purposes

}

John
 
N

Natty Gur

Hi,

I think that you are not using the fill method right. The second
parameter should be the source (DB) TableName. Your code should be like
that:

for (int i =0; i < 6; i++) {
this.sqlDataAdapter1.Fill(dsDF, "DbTableName");
dsDF.Tables.TableName = "Table" + i.ToString()
}

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
 
J

John Sutter

Hi,

I think that you are not using the fill method right. The second
parameter should be the source (DB) TableName. Your code should be like
that:

for (int i =0; i < 6; i++) {
this.sqlDataAdapter1.Fill(dsDF, "DbTableName");
dsDF.Tables.TableName = "Table" + i.ToString()
}


The second parameter is the name of the datatable AFAIK. If your select or
stored procedure comes from seevral tables, what would be the name of the
second parameter if it's the name of a database table?

John
 

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

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,838
Latest member
KandiceChi

Latest Threads

Top