Using DataTableMapping to name different tables in a DataSet

When you use batch SQL statement to retrieve multiple tables and fill a DataSet, the first table is named using the table name specified to the Fill method and subsequent tables are named using the name specified to the Fill method plus one. To avoid this situation we can create a DataTableMapping that maps "Employees1" to "Salary".

SqlDataAdapter dataAd = new SqlDataAdapter("SELECT * FROM Employees; SELECT * FROM Salary;", myConnection);
dataAd .TableMappings.Add("Employees1", "Salary");
DataSet ds = new DataSet();
dataAd .Fill(ds, "Employees");


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: