Bug #9422 Calling MySqlDataAdapter.Fill on DataSet does not provide table name
Submitted: 27 Mar 2005 21:12 Modified: 23 Jun 2005 4:54
Reporter: Arthur Winitchenco Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:1.0.4.20163 OS:Windows (w2k)
Assigned to: Reggie Burnett CPU Architecture:Any

[27 Mar 2005 21:12] Arthur Winitchenco
Description:
Having following code :

DataSet m_data = new DataSet();
string select = "SELECT * FROM sometable";
MySqlDataAdapter adapt = new MySqlDataAdapter(select,m_connection);
adapt.Fill(m_data);

I cannot get to the table by it's name :
m_data.Tables["sometable"] 
return null

Although select was called at table named "sometable" all I get at the dataset is table named "Table" which is quite complicated to find (dont know its index!)

How to repeat:
DataSet m_data = new DataSet();
string select = "SELECT * FROM sometable";
MySqlDataAdapter adapt = new MySqlDataAdapter(select,m_connection);
adapt.Fill(m_data);

int i = m_data.Tables["sometable"] .Rows.Count;

will throw an exception

Suggested fix:
When adapter fills the dataset it should create and add tables with same names as they are
[10 Apr 2005 4:03] Michael Murillo
I didn't think all of the IDataAdapter classes actually populated the table names because of aliases and issues with resolving schema metadata.

For a simple select statement, there should ONLY be one DataTable returned, thus if your select statement executes (even if it returns 0 rows), the index of the DataTable will always be 0:

DataTable dt = m_data.Tables[0];

You can rename the table name by setting the TableName property:

dt.TableName = "sometable";
[19 Apr 2005 18:09] Arthur Winitchenco
What if I have just one dataset and some tables are serializing?

I get up from serialized table collection and get the updates from dbserver.

Having multiple tables in one dataset after each select I have to
find table named "Table" in my datset and merge it with proper table.
Ugly Ugly Ugly Code :-(
[16 May 2005 8:36] Vasily Kishkin
Tested on Win 2000 Sp4,  Microsoft Visual C# .NET , Connector .NET 1.0.4
Test case is attached.
[16 May 2005 8:37] Vasily Kishkin
test program

Attachment: 9422.zip (application/x-zip-compressed, text), 6.54 KiB.

[23 Jun 2005 4:54] Reggie Burnett
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Additional info:

This is not a bug.  If you read the MSDN documentation on IDataAdapter.Fill you will see that if you do not provide any type of tablename mapping, then tables returned into a dataset are named Table, Table1, Table2, Table3, and so on.