新發現:微軟提供的SqlHelper中FillDataset方法一個小Bug )

來源:互聯網
上載者:User

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";”即可
     }
...
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.