Skip to content

Instantly share code, notes, and snippets.

@LinZap
Last active August 30, 2023 07:25
Show Gist options
  • Save LinZap/db56534b0ac9893306e5cb99b3cb66ae to your computer and use it in GitHub Desktop.
Save LinZap/db56534b0ac9893306e5cb99b3cb66ae to your computer and use it in GitHub Desktop.
SQL 可以一次性寫入大量資料

SQL 可以一次性寫入大量資料

版本:ZapLib v2.4.4

新增了 SQL class 中的一個新方法 QuickBulkCopy(),允許一次性大量寫入資料,避免逐筆寫入的效能問題

使用範例

var dt = new DataTable();
dt.Columns.Add("name", typeof(string));
dt.Columns.Add("oid", typeof(int));

for (int i = 0; i < 100; i++)
{
    var row = dt.NewRow();
    row["oid"] = i;
    row["name"] = "user_" + i;
    dt.Rows.Add(row);
}

string Host = "";
string DBName = "";
string User = "";
string Password = "";
SQL db = new SQL(Host, DBName, User, Password);

bool result = db.QuickBulkCopy(dt, "dbo.TestTable");

if (!result)
    Console.WriteLine(db.GetErrorMessage());

輸出結果

image

回 ZapLib v2.4.4 changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment