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");


Comments

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