sqlserver批次更新

來源:互聯網
上載者:User

標籤:

寫過批次更新的代碼,為了方便尋找,發上來

 1 class DBHelper 2     { 3         //操作設定檔 4         Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 5         //先取一次,做為對比的基礎 6         SqlConnection conn = new SqlConnection(); 7         SqlCommand comm = new SqlCommand(); 8         //連結資料庫 9         public void Open()10         {11             conn = new SqlConnection(config.AppSettings.Settings["connstr"].Value);12             conn.Open();13         }14         //中斷連線15         public void Close()16         {17             conn.Close();18         }19         //執行sql,並返回第一行第一列20         public object ExecuteScalar(string sql)21         {22             comm.CommandText = sql;23             comm.Connection = conn;24             return comm.ExecuteScalar();25         }26         //執行sql,並返回執行結果27         public DataTable GetResult(string sql)28         {29             SqlDataAdapter sda = new SqlDataAdapter(sql, conn);30             DataTable dt = new DataTable();31             sda.Fill(dt);32             return dt;33         }34         //執行sql35         public void ExecuteNonQuery(string sql)36         {37             comm.CommandText = sql;38             comm.ExecuteNonQuery();39         }40         //批次更新41         public void Update(DataTable dt, string tablename)42         {43             using (SqlBulkCopy sqlcopy = new SqlBulkCopy(conn))44             {45                 sqlcopy.BulkCopyTimeout = 10000;46                 sqlcopy.DestinationTableName = tablename;47                 sqlcopy.WriteToServer(dt);48             }49         }50     }

 

sqlserver批次更新

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.