What is the fastest way to insert 100 000 records into an MDB file in C#

前端 未结 3 1887
迷失自我
迷失自我 2020-12-21 15:54

I know this questions is rather general, but I have searched the whole day and I haven\'t been able to find the proper way to do this.

Here is my code to insert some

3条回答
  •  渐次进展
    2020-12-21 16:30

    (Bonus answer:)

    In case anyone is wondering whether an OleDbDataAdapter can insert the rows faster, it seems not. The following code does create the 100,000 records...

    var da = new OleDbDataAdapter("SELECT [ID], [Title], [Price], [Tag], [Author] FROM [tblBooks] WHERE False", con);
    var cb = new OleDbCommandBuilder(da);
    cb.QuotePrefix = "["; cb.QuoteSuffix = "]";
    var dt = new System.Data.DataTable();
    da.Fill(dt);
    for (int i = 0; i < 100000; i++)
    {
        System.Data.DataRow dr = dt.NewRow();
        dr["Title"] = "Dummy Text 1";
        dr["Price"] = 10;
        dr["Tag"] = "Dummy Text 2";
        dr["Author"] = "Dummy Text 3";
        dt.Rows.Add(dr);
    }
    da.Update(dt);
    

    ...but it takes about 30% longer to run than the original code in the question.

提交回复
热议问题