Why Fill creates two datatables in dataset?

  • Thread starter Thread starter John Sutter
  • Start date Start date
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
 
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
 
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
 
Back
Top