I don't know if anyone uses the Microsoft.Applications.Data.SqlHelper class. I've just discover a small bug when using the
the FillDataset method to populate a dataset with a stored procedure that returns multiple recordsets.
In the version I was using the names of the table sources were Table, Table1, Table2. However they were being added to the TablemMappings collection
incorrectly: Table, Table1, Table12, Table123, etc.
While this obviously works for the first two recordsets, anyother recordsets except for 12, 123, 1234, 12345 would not be mapped correctly.
Here's the function that needs to be replaced in the SqlHelper class, line 1816 in my version.
private static void FillDataset(SqlConnection connection, SqlTransaction transaction, CommandType commandType,
string commandText, DataSet dataSet, string[] tableNames,
params SqlParameter[] commandParameters)
{
if( connection == null ) throw new ArgumentNullException( "connection" );
if( dataSet == null ) throw new ArgumentNullException( "dataSet" );
// Create a command and prepare it for execution
SqlCommand command = new SqlCommand();
bool mustCloseConnection = false;
PrepareCommand(command, connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection );
// Create the DataAdapter & DataSet
using( SqlDataAdapter dataAdapter = new SqlDataAdapter(command) )
{
// Add the table mappings specified by the user
if (tableNames != null && tableNames.Length > 0)
{
string tableName = SqlDataAdapter.DefaultSourceTableName;
for (int index=0; index < tableNames.Length; index++)
{
if( tableNames[index] == null || tableNames[index].Length == 0 ) throw new ArgumentException( "The tableNames parameter must contain a list of tables, a value was provided as null or empty string.", "tableNames" );
dataAdapter.TableMappings.Add(tableName, tableNames[index]);
tableName = SqlDataAdapter.DefaultSourceTableName + (index + 1).ToString();
}
}
// Fill the DataSet using default values for DataTable names, etc
dataAdapter.Fill(dataSet);
// Detach the SqlParameters from the command object, so they can be used again
command.Parameters.Clear();
}
if( mustCloseConnection )
connection.Close();
}