FillDataset(SqlConnection connection, CommandType commandType,
string commandText, DataSet dataSet, string[] tableNames)
當調用此方法,並指定映射表名數組,對應參數tableNames
若元素超過3個,即指定表名超過3個時,從第3個表名開始返回的將是系統預設的表名
而非使用者指定的表名(如,指定"header" "detail" "relation",第3個返回了Table2)
此Bug原因在這裡:
private static void FillDataset(SqlConnection connection, SqlTransaction transaction, CommandType commandType,
string commandText, DataSet dataSet, string[] tableNames,
params SqlParameter[] commandParameters)
{
...
string tableName = "Table";
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 += (index + 1).ToString(); //若超過3個表,則
tableName會變成Table11,Table111,返回映射表名即為Table2,Table3了
解決方案即在此句前面加“tableName = "Table";”即可
}
...
}