Popular Posts
CTE, recursive search WITH DepartmentSearch(DeptID, DeptParent, DeptName, OuID) AS (     -- 找出簽核者所屬部門     SELECT d.DeptID, d.DeptParent, d.DeptName, d.OuID     FR... LogonUser Function : impersonate a windows user // This sample demonstrates the use of the WindowsIdentity class to impersonate a user. // IMPORTANT NOTES:  // This sample can be run only ... Invoke Gson#toJson() on anonymous class Create a anonymous object and try to serialize instance via gson. The code is below Result of execution. null result when serialize a an...
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);
    }
}