demoshop

NEWS

demo, trying to be the best.

站內搜尋載入中...

將資料大量寫入資料庫(使用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();
    }