將資料大量寫入資料庫(使用SqlDataSoure)
- 3440
- 1
上一篇介紹『將資料大量寫入資料庫時的優化寫法』是利用ADO.NET的寫法,但有些開發者習慣或是愛用等因素就是要用SqlDataSoure來完成,所以就出現了此篇文章啦
此篇只列出最重要的部份,您應該看了就懂了,至於頁面上的配置和該在什麼事件處理因人而異,demo就不多介紹了。
:此篇的SqlDataSource名稱為SqlDataSource2
this.SqlDataSource2.InsertCommand = "INSERT INTO [Table1] ([name]) VALUES (@name)";//將Inster的SQL語句寫好
this.SqlDataSource2.InsertParameters.Add("name", TypeCode.String, "");//宣告參數
int i;
for (i = 1; i <= 100; i++)
{
SqlDataSource2.InsertParameters["name"].DefaultValue = string.Format("第{0}筆", i);
SqlDataSource2.Insert();
}
網友回應
- Jerry Huang

- 發表於: 2011-07-11
- 請問一下,
我有程式要從 XML 檔讀出數筆資料,
再新增到 SQL SERVER,適合用這個嗎? -
您可能要參考使用SqlBulkCopy將資料批次寫入資料庫 | demo小鋪
回覆於: 2011-07-11