DataTable dt =NewDataTable (); System.Data.SqlClient.SqlConnection CNN=NewSystem.Data.SqlClient.SqlConnection ("Connection String"); System.Data.SqlClient.SqlCommand cm=NewSystem.Data.SqlClient.SqlCommand (); Cm. Connection=CNN; Cnn. Open (); System.Data.SqlClient.SqlTransaction Trans=CNN. BeginTransaction (); Try { foreach(DataRow Drinchdt. Rows) {Cm.commandtext="Update [table] set [Quantity] = @amount where ProductID = @productID"; Cm. Parameters.Add ("@amount", SqlDbType.Int); Cm. parameters["@amount"]. Value = Convert.ToInt32 (dr["Amount"]); Cm. Parameters.Add ("@productID", SqlDbType.VarChar); Cm. parameters["@productID"]. Value = dr["ProductID"]. ToString (); Cm. ExecuteNonQuery (); } trans.commit (); } Catch{trans. Rollback (); } finally{CNN. Close (); Trans. Dispose (); Cnn. Dispose (); }
Simple Example
Simple examples of C # things (GO)