Sqltransaction 是用在多sql任务写数据库时的
Code
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString))
{
conn.Open();
SqlTransaction trans = conn.BeginTransaction();
try
{
foreach (DataRow row in dt.Rows)
//DataRow row = dt.Rows[0];
{
//PriceProvider.ModifySupplier(null, txtCustomerID.Text, row["productVariantID"].ToString(), ddlSupp.SelectedValue);
PriceProvider.ModifySalesPricePerProduct(trans, txtCustomerID.Text, row["ProductVariantID"].ToString(),
ddlBaseonPriceLevel1.SelectedItem.Text, txtCustomerID.Text, txtFormula1.Text, ddlCurrency1.SelectedItem.Text,
Convert.ToDateTime(TxtValidateEndDate1.Text), txtRemarks.Text);
//lblmsgSupp.Text =lblmsgSupp.Text+ row["productVariantID"].ToString();
}
trans.Commit();
trans.Dispose();
trans = null;
lblmsgSupp.Text = "succeed";
initDataTable();
}
catch
{
// trans1.Rollback();
trans.Rollback();
//lblmsgSupp.Text = conn.ConnectionTimeout.ToString();
throw;
}
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionString))
{
conn.Open();
SqlTransaction trans = conn.BeginTransaction();
try
{
foreach (DataRow row in dt.Rows)
//DataRow row = dt.Rows[0];
{
//PriceProvider.ModifySupplier(null, txtCustomerID.Text, row["productVariantID"].ToString(), ddlSupp.SelectedValue);
PriceProvider.ModifySalesPricePerProduct(trans, txtCustomerID.Text, row["ProductVariantID"].ToString(),
ddlBaseonPriceLevel1.SelectedItem.Text, txtCustomerID.Text, txtFormula1.Text, ddlCurrency1.SelectedItem.Text,
Convert.ToDateTime(TxtValidateEndDate1.Text), txtRemarks.Text);
//lblmsgSupp.Text =lblmsgSupp.Text+ row["productVariantID"].ToString();
}
trans.Commit();
trans.Dispose();
trans = null;
lblmsgSupp.Text = "succeed";
initDataTable();
}
catch
{
// trans1.Rollback();
trans.Rollback();
//lblmsgSupp.Text = conn.ConnectionTimeout.ToString();
throw;
}