Popular Posts
DNS SERVER LIST Google 8.8.8.8 8.8.4.4 TWNIC 192.83.166.11 211.72.210.250 HiNet 168.95.1.1 168.95.192.1 Seednet 北區 DNS (台北, 桃園, 新竹, 宜蘭, 花蓮, 苗栗) 139.... DataList paging //利用PageDataSource來做分頁功能 PagedDataSource pds = new PagedDataSource(); //將PageDataSource綁定SqlDataSource pds.DataSource = SqlDataSource1.Selec... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
Stats
Batch insert using SqlDataAdapter
string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["JobHunter"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connStr))
{
    conn.Open();

    #region
    string JobID = Guid.NewGuid().ToString();
    HashSet<string> JobCategory = new HashSet<string>(new string[] { 
       "Windows 8標準搭載のセキュリティ Windows Defenderとは - トレンドマイクロ",
        "Windows 8対応 パスワードマネージャー Modern UI版 - トレンドマイクロ",
        "Windows 8にもマルウェア対策は必須 - トレンドマイクロ",
        "Windows 8にもWeb脅威対策は必須 - トレンドマイクロ",
        "Windows 8でも、面倒なパスワード入力はしない。 - トレンドマイクロ",
        "Windows 8 最新のセキュリティにも対応 - トレンドマイクロ",
        "Windows 8 もウイルスバスタークラウドで安心! border=",
        "Windows 8 のセキュリティ対策もウイルスバスター クラウド - トレンドマイクロ",
        "Windows 8 Modern UI向け無料アプリ Windows ストアアプリ",
        "Windows 8 Modern UI向け Windows ストアアプリ - トレンドマイクロ",
        "Windows 8 Modern UI向け 3種類のWindows ストアアプリ - トレンドマイクロ"
    });
    #endregion

    using (System.Data.SqlClient.SqlDataAdapter adapter 
        = new System.Data.SqlClient.SqlDataAdapter(@"select top 0 * from JobCategory", conn))
    {
        // add insert command
        adapter.InsertCommand = new SqlCommand(@"insert into JobCategory values(@JobID, @CategoryName);", conn);
        adapter.InsertCommand.Parameters.Add("@JobID", SqlDbType.VarChar, 50, "JobID");
        adapter.InsertCommand.Parameters.Add("@CategoryName", SqlDbType.NVarChar, 50, "CategoryName");
        adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;

        DataTable dt = new DataTable();
        adapter.Fill(dt);

        foreach (string name in JobCategory)
        {
            dt.Rows.Add(JobID, name);
        }

        // one-time update
        adapter.UpdateBatchSize = 0;
        adapter.Update(dt);
    }
}