本文整理汇总了C#中System.Data.SqlClient.SqlTransaction.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# SqlTransaction.Commit方法的具体用法?C# SqlTransaction.Commit怎么用?C# SqlTransaction.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlTransaction
的用法示例。
在下文中一共展示了SqlTransaction.Commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteCopy
public int DeleteCopy(LIB.CopyDTO copy, SqlTransaction trans)
{
bool isInScopeCreated = false;
int rs;
if (trans == null)
{
isInScopeCreated = true;
trans = ConnectionManager.Con.BeginTransaction("CAT_CRE_TRANSACT");
}
CopyDAO dao = new CopyDAO();
rs = dao.DeleteCopy(copy, trans);
if (isInScopeCreated)
{
if (rs == 0)
trans.Rollback();
else
trans.Commit();
}
return rs;
}
示例2: addunit
public void addunit()
{
tr = Conn.BeginTransaction();
try
{
sb = new StringBuilder();
sb.Append("INSERT INTO UNIT (UnitId,UnitName,UnitNameEng)");
sb.Append(" VALUES (@UnitId,@UnitName,@UnitNameEng)");
string sqlAdd;
sqlAdd = sb.ToString();
com.CommandText = sqlAdd;
com.CommandType = CommandType.Text;
com.Connection = Conn;
com.Transaction = tr;
com.Parameters.Clear();
com.Parameters.Add("@UnitId", SqlDbType.NVarChar).Value = txtUnitId.Text.Trim();
com.Parameters.Add("@UnitName", SqlDbType.NVarChar).Value = txtUnitName.Text.Trim();
com.Parameters.Add("@UnitNameEng", SqlDbType.NVarChar).Value = txtUnitNameEng.Text.Trim();
com.ExecuteNonQuery();
tr.Commit();
}
catch
{
MessageBox.Show("คุณป้อนรหัสหน่วยนับสินค้าซ้ำ !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
tr.Rollback();
}
}
示例3: ExecuteNonQuery
public void ExecuteNonQuery(SqlCommand sqlCmd)
{
using (SqlConnection sqlConn = new SqlConnection())
{
try
{
sqlConn.ConnectionString = strSqlConnectionString;
if (sqlConn.State != ConnectionState.Open)
{
sqlConn.Open();
}
sqlTrans = sqlConn.BeginTransaction("ExecuteNonQueryTransaction");
sqlCmd.Connection = sqlConn;
sqlCmd.Transaction = sqlTrans;
sqlCmd.ExecuteNonQuery();
sqlTrans.Commit();
}
catch (SqlException exSql)
{
SqlException ex = exSql;
try
{
if (sqlTrans != null)
{
sqlTrans.Rollback("ExecuteNonQueryTransaction");
}
}
catch (SqlException exRollback)
{
ex = exRollback;
}
throw ex;
}
}
}
示例4: getVector
public DataTable getVector(string SQL)
{
DataTable dt = new DataTable();
try
{
if (_DBType.Equals("SQL"))
{
tx_Sql = cn_Sql.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn_Sql;
cmd.CommandText = SQL;
cmd.CommandType = CommandType.Text;
cmd.Transaction = tx_Sql;
SqlDataReader dr = cmd.ExecuteReader();
dt.Load(dr);
tx_Sql.Commit();
return dt;
}
}
catch (Exception e)
{
}
return null;
}
示例5: Import
public void Import(string connectionString, StatbookModel statbook, bool assumeATeams)
{
_connection = new SqlConnection(connectionString);
try
{
_connection.Open();
_transaction = _connection.BeginTransaction();
// insert leagues
LeagueGateway leagueGateway = new LeagueGateway(_connection, _transaction);
var leagues = leagueGateway.GetAllLeagues();
League homeLeague = leagues.FirstOrDefault(l => l.Name.ToLower() == statbook.HomeTeam.LeagueName.ToLower());
League awayLeague = leagues.FirstOrDefault(l => l.Name.ToLower() == statbook.AwayTeam.LeagueName.ToLower());
int maxID = leagues.Select(l => l.ID).Max();
if(homeLeague == null)
{
homeLeague = leagueGateway.GetLeague(maxID + 1, statbook.HomeTeam.LeagueName, statbook.Date, false);
maxID++;
}
if(awayLeague == null)
{
awayLeague = leagueGateway.GetLeague(maxID + 1, statbook.AwayTeam.LeagueName, statbook.Date, false);
maxID++;
}
// insert teams
TeamGateway teamGateway = new TeamGateway(_connection, _transaction);
Team homeTeam, awayTeam;
if (assumeATeams)
{
homeTeam = teamGateway.GetATeam(homeLeague.ID);
awayTeam = teamGateway.GetATeam(awayLeague.ID);
}
else
{
homeTeam = teamGateway.GetTeam(statbook.HomeTeam.Name, homeLeague.ID, "A", false);
awayTeam = teamGateway.GetTeam(statbook.AwayTeam.Name, awayLeague.ID, "A", false);
}
// insert bout
BoutGateway boutGateway = new BoutGateway(_connection, _transaction);
if(!boutGateway.DoesBoutExist(homeTeam.ID, awayTeam.ID, statbook.Date))
{
Bout bout = boutGateway.GetBout(homeTeam.ID, awayTeam.ID, statbook.Date);
BoutDataImport(statbook, bout, homeTeam, awayTeam);
}
else
{
// bout already exists
Console.WriteLine(string.Format("Bout between {0} and {1} on {2} already exists.", homeTeam.Name, awayTeam.Name, statbook.Date));
}
_transaction.Commit();
}
finally
{
_connection.Close();
}
}
示例6: CreatePaySalary
public int CreatePaySalary(PaySalary newPaySalary)
{
int result = -1;
try
{
conn = db.openConn();
tr = conn.BeginTransaction();
sb = new StringBuilder();
sb.Remove(0, sb.Length);
sb.Append("INSERT INTO tbPaySalary(payID,psnCode,payStartDate,payEndDate,period,salary,revenceAll,netIncome,total,pSalary,pOt,pWork,ppSo,psLa,psLast,psLess,psReam,psIns,psPenalty)");
sb.Append(" VALUES (@payID,@psnCode,@payStartDate,@payEndDate,@period,@salary,@revenceAll,@netIncome,@total,@pSalary,@pOt,@pWork,@ppSo,@psLa,@psLast,@psLess,@psReam,@psIns,@psPenalty)");
string sqlsave;
sqlsave = sb.ToString();
comm = new SqlCommand();
comm.Connection = conn;
comm.Transaction = tr;
comm.CommandText = sqlsave;
comm.Parameters.Clear();
comm.Parameters.Add("@payID", SqlDbType.NVarChar).Value = newPaySalary.payID;
comm.Parameters.Add("@psnCode", SqlDbType.NVarChar).Value = newPaySalary.psnCode;
comm.Parameters.Add("@payStartDate", SqlDbType.NVarChar).Value = newPaySalary.payStartDate;
comm.Parameters.Add("@payEndDate", SqlDbType.NVarChar).Value = newPaySalary.payEndDate;
comm.Parameters.Add("@period", SqlDbType.NVarChar).Value = newPaySalary.period;
comm.Parameters.Add("@salary", SqlDbType.NVarChar).Value = newPaySalary.salary;
comm.Parameters.Add("@revenceAll", SqlDbType.NVarChar).Value = newPaySalary.revenceAll;
comm.Parameters.Add("@netIncome", SqlDbType.NVarChar).Value = newPaySalary.netIncome;
comm.Parameters.Add("@total", SqlDbType.NVarChar).Value = newPaySalary.total;
comm.Parameters.Add("@pSalary", SqlDbType.NVarChar).Value = newPaySalary.pSalary;
comm.Parameters.Add("@pOt", SqlDbType.NVarChar).Value = newPaySalary.pOt;
comm.Parameters.Add("@pWork", SqlDbType.NVarChar).Value = newPaySalary.pWork;
comm.Parameters.Add("@ppSo", SqlDbType.NVarChar).Value = newPaySalary.ppSo;
comm.Parameters.Add("@psLa", SqlDbType.NVarChar).Value = newPaySalary.psLa;
comm.Parameters.Add("@psLast", SqlDbType.NVarChar).Value = newPaySalary.psLast;
comm.Parameters.Add("@psLess", SqlDbType.NVarChar).Value = newPaySalary.psLess;
comm.Parameters.Add("@psReam", SqlDbType.NVarChar).Value = newPaySalary.psReam;
comm.Parameters.Add("@psIns", SqlDbType.NVarChar).Value = newPaySalary.psIns;
comm.Parameters.Add("@psPenalty", SqlDbType.NVarChar).Value = newPaySalary.psPenalty;
comm.ExecuteNonQuery();
tr.Commit();
result = 1;
}
catch (Exception ex)
{
tr.Rollback();
conn.Close();
return result;
throw ex;
}
finally
{
conn.Close();
}
return result;
}
示例7: ExecuteDataset
public static DataSet ExecuteDataset(SqlCommand command, SqlConnection connection, SqlTransaction transaction)
{
bool mustCloseConnection = false;
#region Check
if (connection == null) throw new ArgumentNullException("connection");
if (command == null) throw new ArgumentNullException("command");
if (connection.State != ConnectionState.Open)
{
mustCloseConnection = true;
connection.Open();
}
else
{
mustCloseConnection = false;
}
if (transaction != null)
{
if (transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
command.Transaction = transaction;
}
#endregion
command.Connection = connection;
command.Transaction = transaction;
using (SqlDataAdapter da = new SqlDataAdapter(command))
{
DataSet retval = new DataSet();
if (transaction == null)
{
da.Fill(retval);
}
else
{
try
{
da.Fill(retval);
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
throw ex;
}
}
if (mustCloseConnection)
connection.Close();
return retval;
}
}
示例8: CommitTransaccion
public static void CommitTransaccion(SqlTransaction tran)
{
try
{
tran.Commit();
}
catch (Exception ex)
{ throw new Exception("CommitTransaccion - DataLibrary", ex); }
}
示例9: btnAdd_Click
private void btnAdd_Click(object sender, EventArgs e)
{
if (txtUnitSaleName.Text.Trim() == "")
{
MessageBox.Show("กรุณาป้อนชื่อหน่วยก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtUnitSaleName.Focus();
return;
}
if (txtUnitSaleNameEng.Text.Trim() == "")
{
MessageBox.Show("กรุณาป้อนชื่อหน่วยก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtUnitSaleNameEng.Focus();
return;
}
if (MessageBox.Show("คุณต้องการเพิ่มหน่วยนับสินค้าใหม่ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
tr = Conn.BeginTransaction();
try
{
sb = new StringBuilder();
sb.Append("INSERT INTO UNITSALE (UnitSaleId,UnitSaleName,UnitSaleNameEng)");
sb.Append(" VALUES (@UnitSaleId,@UnitSaleName,@UnitSaleNameEng)");
string sqlAdd;
sqlAdd = sb.ToString();
com.CommandText = sqlAdd;
com.CommandType = CommandType.Text;
com.Connection = Conn;
com.Transaction = tr;
com.Parameters.Clear();
com.Parameters.Add("@UnitSaleId", SqlDbType.NVarChar).Value = txtUnitSaleId.Text.Trim();
com.Parameters.Add("@UnitSaleName", SqlDbType.NVarChar).Value = txtUnitSaleName.Text.Trim();
com.Parameters.Add("@UnitSaleNameEng", SqlDbType.NVarChar).Value = txtUnitSaleNameEng.Text.Trim();
com.ExecuteNonQuery();
tr.Commit();
MessageBox.Show("เพิ่มหน่วยนับสินค้าใหม่ เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
ClearAllData();
ShowData();
FormatdgvUnitSaleList();
UnitSaleId();
}
catch
{
MessageBox.Show("คุณป้อนรหัสหน่วยนับสินค้าซ้ำ !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
tr.Rollback();
}
}
txtUnitSaleId.Focus();
}
示例10: CreateLabel
public int CreateLabel(Label newLabel)
{
int result = -1;
try
{
conn = db.openConn();
tr = conn.BeginTransaction();
sb = new StringBuilder();
sb.Remove(0, sb.Length);
sb.Append("INSERT INTO Label(Id,PartName,SerialNo,PrintTime,Line,Ckt,Model,OilType,OilWeight,Status,Run,MM)");
sb.Append(" VALUES (@Id,@PartName,@SerialNo,@PrintTime,@Line,@Ckt,@Model,@OilType,@OilWeight,@Status,@Run,@MM)");
string sqlsave;
sqlsave = sb.ToString();
comm = new SqlCommand();
comm.Connection = conn;
comm.Transaction = tr;
comm.CommandText = sqlsave;
comm.Parameters.Clear();
comm.Parameters.Add("@Id", SqlDbType.NVarChar).Value = newLabel.Id;
comm.Parameters.Add("@PartName", SqlDbType.NVarChar).Value = newLabel.PartName;
comm.Parameters.Add("@SerialNo", SqlDbType.NVarChar).Value = newLabel.SerialNo;
comm.Parameters.Add("@PrintTime", SqlDbType.DateTime).Value =newLabel.PrintTime;
comm.Parameters.Add("@Line", SqlDbType.NVarChar).Value = newLabel.Line;
comm.Parameters.Add("@Ckt", SqlDbType.NVarChar).Value = newLabel.Ckt;
comm.Parameters.Add("@Model", SqlDbType.NVarChar).Value = newLabel.Model;
comm.Parameters.Add("@OilType", SqlDbType.NVarChar).Value = newLabel.OilType;
comm.Parameters.Add("@OilWeight", SqlDbType.NVarChar).Value = newLabel.OilWeight;
comm.Parameters.Add("@Status", SqlDbType.NVarChar).Value = newLabel.Status;
comm.Parameters.Add("@Run", SqlDbType.NVarChar).Value = newLabel.Run;
comm.Parameters.Add("@MM", SqlDbType.NVarChar).Value = newLabel.MM;
comm.ExecuteNonQuery();
tr.Commit();
logger.Fatal(" Save Complate ");
result = 1;
}
catch (Exception ex)
{
logger.Fatal(" Save Not complate "+ex.Message);
tr.Rollback();
conn.Close();
return result;
throw ex;
}
finally
{
conn.Close();
}
return result;
}
示例11: CreateInjectionCabinetLabel
public int CreateInjectionCabinetLabel(InjectionPanalLabels newInjectionCabinetLabel)
{
int result = -1;
try
{
conn = db.openConn();
tr = conn.BeginTransaction();
sb = new StringBuilder();
sb.Remove(0, sb.Length);
sb.Append("INSERT INTO injection_panal_labels(barcode,part,date,serial,shift,rev,matterial_no,lot_no,color_no,machine_no,mold_no,user_create_name,create_date,status)");
sb.Append(" VALUES (@barcode,@part,@date,@serial,@shift,@rev,@matterial_no,@lot_no,@color_no,@machine_no,@mold_no,@user_create_name,@create_date,@status)");
string sqlsave;
sqlsave = sb.ToString();
comm = new SqlCommand();
comm.Connection = conn;
comm.Transaction = tr;
comm.CommandText = sqlsave;
comm.Parameters.Clear();
comm.Parameters.Add("@barcode", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.BarCode;
comm.Parameters.Add("@part", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.Part;
comm.Parameters.Add("@date", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.date;
comm.Parameters.Add("@serial", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.Serial;
comm.Parameters.Add("@shift", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.Shift;
comm.Parameters.Add("@rev", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.Rev;
comm.Parameters.Add("@matterial_no", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.MatterialNo;
comm.Parameters.Add("@lot_no", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.LotNo;
comm.Parameters.Add("@color_no", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.ColorNo;
comm.Parameters.Add("@machine_no", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.MachineNo;
comm.Parameters.Add("@mold_no", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.MoldNo;
comm.Parameters.Add("@user_create_name", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.UserCreateName;
comm.Parameters.Add("@create_date", SqlDbType.DateTime).Value = newInjectionCabinetLabel.CreateDate;
comm.Parameters.Add("@status", SqlDbType.NVarChar).Value = newInjectionCabinetLabel.Status;
comm.ExecuteNonQuery();
tr.Commit();
result = 1;
}
catch (Exception ex)
{
tr.Rollback();
conn.Close();
return result;
throw ex;
}
finally
{
conn.Close();
}
return result;
}
示例12: CreatePringtingLabel
public int CreatePringtingLabel(PrintingLabels newPrintingLabels)
{
int result = -1;
try
{
conn = db.openConn();
tr = conn.BeginTransaction();
sb = new StringBuilder();
sb.Remove(0, sb.Length);
sb.Append("INSERT INTO printing_labels(barcode,part,product_date,serial,shift,rev,color_no,process,mold_no,user_create_name,create_date,status)");
sb.Append(" VALUES (@barcode,@part,@product_date,@serial,@shift,@rev,@color_no,@process,@mold_no,@user_create_name,@create_date,@status)");
string sqlsave;
sqlsave = sb.ToString();
comm = new SqlCommand();
comm.Connection = conn;
comm.Transaction = tr;
comm.CommandText = sqlsave;
comm.Parameters.Clear();
comm.Parameters.Add("@barcode", SqlDbType.NVarChar).Value = newPrintingLabels.BarCode;
comm.Parameters.Add("@part", SqlDbType.NVarChar).Value = newPrintingLabels.Part;
comm.Parameters.Add("@product_date", SqlDbType.NVarChar).Value = newPrintingLabels.ProductDate;
comm.Parameters.Add("@serial", SqlDbType.NVarChar).Value = newPrintingLabels.Serial;
comm.Parameters.Add("@shift", SqlDbType.NVarChar).Value = newPrintingLabels.Shift;
comm.Parameters.Add("@rev", SqlDbType.NVarChar).Value = newPrintingLabels.Rev;
comm.Parameters.Add("@color_no", SqlDbType.NVarChar).Value = newPrintingLabels.ColorNo;
comm.Parameters.Add("@process", SqlDbType.NVarChar).Value = newPrintingLabels.Process;
comm.Parameters.Add("@mold_no", SqlDbType.NVarChar).Value = newPrintingLabels.Mold;
comm.Parameters.Add("@user_create_name", SqlDbType.NVarChar).Value = newPrintingLabels.UserCreateName;
comm.Parameters.Add("@create_date", SqlDbType.DateTime).Value = newPrintingLabels.CreateDate;
comm.Parameters.Add("@status", SqlDbType.NVarChar).Value = newPrintingLabels.Status;
comm.ExecuteNonQuery();
tr.Commit();
result = 1;
}
catch (Exception ex)
{
tr.Rollback();
conn.Close();
return result;
throw ex;
}
finally
{
conn.Close();
}
return result;
}
示例13: CreateMillin
public int CreateMillin(Millin newMillin)
{
int result = -1;
try
{
conn = db.openConn();
tr = conn.BeginTransaction();
sb = new StringBuilder();
sb.Remove(0, sb.Length);
sb.Append("INSERT INTO tbMillin(psnCode,cause,mFormat,note,mdateStart,mhurStart,mdateEnd,mhurEnd,mdateAll,mhurAll,mless,mtime)");
sb.Append(" VALUES (@psnCode,@cause,@mFormat,@note,@mdateStart,@mhurStart,@mdateEnd,@mhurEnd,@mdateAll,@mhurAll,@mless,@mtime)");
string sqlsave;
sqlsave = sb.ToString();
comm = new SqlCommand();
comm.Connection = conn;
comm.Transaction = tr;
comm.CommandText = sqlsave;
comm.Parameters.Clear();
comm.Parameters.Add("@psnCode", SqlDbType.NVarChar).Value = newMillin.psnCode;
comm.Parameters.Add("@cause", SqlDbType.NVarChar).Value = newMillin.cause;
comm.Parameters.Add("@mFormat", SqlDbType.NVarChar).Value = newMillin.mFormat;
comm.Parameters.Add("@note", SqlDbType.NVarChar).Value = newMillin.note;
comm.Parameters.Add("@mdateStart", SqlDbType.NVarChar).Value = newMillin.mdateStart;
comm.Parameters.Add("@mhurStart", SqlDbType.NVarChar).Value = newMillin.mhurStart;
comm.Parameters.Add("@mdateEnd", SqlDbType.NVarChar).Value = newMillin.mdateEnd;
comm.Parameters.Add("@mhurEnd", SqlDbType.NVarChar).Value = newMillin.mhurEnd;
comm.Parameters.Add("@mdateAll", SqlDbType.NVarChar).Value = newMillin.mdateAll;
comm.Parameters.Add("@mhurAll", SqlDbType.NVarChar).Value = newMillin.mhurAll;
comm.Parameters.Add("@mless", SqlDbType.NVarChar).Value = newMillin.mless;
comm.Parameters.Add("@mtime", SqlDbType.NVarChar).Value = newMillin.mtime;
comm.ExecuteNonQuery();
tr.Commit();
result = 1;
}
catch (Exception ex)
{
tr.Rollback();
conn.Close();
return result;
throw ex;
}
finally
{
conn.Close();
}
return result;
}
示例14: CreateFinishingLabel
public int CreateFinishingLabel(FinshingLabel newFinshingLabel)
{
int result = -1;
try
{
conn = db.openConn();
tr = conn.BeginTransaction();
sb = new StringBuilder();
sb.Remove(0, sb.Length);
sb.Append("INSERT INTO finishing_labels(barcode,complete_no,rev,place_name,product_barcode_date,product_text_date,line,shift,serial,print_date,user_create_name,status)");
sb.Append(" VALUES (@barcode,@complete_no,@rev,@place_name,@product_barcode_date,@product_text_date,@line,@shift,@serial,@print_date,@user_create_name,@status)");
string sqlsave;
sqlsave = sb.ToString();
comm = new SqlCommand();
comm.Connection = conn;
comm.Transaction = tr;
comm.CommandText = sqlsave;
comm.Parameters.Clear();
comm.Parameters.Add("@barcode", SqlDbType.NVarChar).Value = newFinshingLabel.Barcode;
comm.Parameters.Add("@complete_no", SqlDbType.NVarChar).Value = newFinshingLabel.CompleteNo;
comm.Parameters.Add("@rev", SqlDbType.NVarChar).Value = newFinshingLabel.Rev;
comm.Parameters.Add("@place_name", SqlDbType.NVarChar).Value = newFinshingLabel.PlaceName;
comm.Parameters.Add("@product_barcode_date", SqlDbType.NVarChar).Value = newFinshingLabel.ProductBarCodeDate;
comm.Parameters.Add("@product_text_date", SqlDbType.NVarChar).Value = newFinshingLabel.ProductTextDate;
comm.Parameters.Add("@line", SqlDbType.NVarChar).Value = newFinshingLabel.Line;
comm.Parameters.Add("@shift", SqlDbType.NVarChar).Value = newFinshingLabel.Shift;
comm.Parameters.Add("@serial", SqlDbType.NVarChar).Value = newFinshingLabel.Serial;
comm.Parameters.Add("@print_date", SqlDbType.DateTime).Value = newFinshingLabel.PrintDate;
comm.Parameters.Add("@user_create_name", SqlDbType.NVarChar).Value = newFinshingLabel.UserCreateName;
comm.Parameters.Add("@status", SqlDbType.NVarChar).Value = newFinshingLabel.Status ;
comm.ExecuteNonQuery();
tr.Commit();
result = 1;
}
catch (Exception ex)
{
tr.Rollback();
conn.Close();
return result;
throw ex;
}
finally
{
conn.Close();
}
return result;
}
示例15: deletesupplier
public void deletesupplier()
{
if (MessageBox.Show("คุณต้องการลบผู้ขาย ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
tr = Conn.BeginTransaction();
try
{
sb = new StringBuilder();
sb.Append("DELETE SUPPLIER");
sb.Append(" WHERE ([email protected])");
string sqlDelete;
sqlDelete = sb.ToString();
com.CommandText = sqlDelete;
com.CommandType = CommandType.Text;
com.Connection = Conn;
com.Transaction = tr;
com.Parameters.Clear();
com.Parameters.Add("@SupplierId", SqlDbType.NVarChar).Value = txtSupplierID.Text.Trim();
int result;
result = com.ExecuteNonQuery();
if (result == 0)
{
tr.Rollback();
MessageBox.Show("ข้อมูลที่ต้องการลบไม่ถูกต้อง !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtSupplierID.SelectAll();
}
else
{
tr.Commit();
//MessageBox.Show("ลบชื่อหน่วยนับสินค้า เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
// ClearAllData();//Clear ข้อมูลจาก textbox
ShowData();
FormatDgvSupplierList();
btnAdd.Enabled = true;
btnEdit.Enabled = false;
btnDelete.Enabled = false;
}
}
catch (Exception ex)
{
tr.Rollback();
MessageBox.Show("เกิดข้อผิดพลาด เนื่องจาก " + ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}