每次使用调试器时,都会执行我的一个存储过程,即使我在到达负责将数据保存到数据库的代码行之前停止调试器也是如此。
我怎样才能防止这种情况发生?我不想在数据库中有不完整的行。
POrder po = new POrder();
po.PODate = DateTime.Parse(txtPODate.Text); <-- Breakpoint here
po.POVendorID = int.Parse(ddPOVendors.SelectedValue); <-- Stop Debugging here
我还没有到达po.AddNewOrder
并且我停止了调试器,所以我还没有执行存储过程
po.AddNewOrder();
POrder
班级:
public DateTime PODate { get; set; }
public int POVendorID { get; set; }
public void AddNewOrder()
{
SqlConnection con = new SqlConnection(ss.GetConectionString());
SqlCommand cmd = new SqlCommand("uspAddNewPOrder", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter parPODate = new SqlParameter("@PODate", SqlDbType.Date);
parPODate.Value = PODate;
cmd.Parameters.Add(parPODate);
SqlParameter parPOVendorID = new SqlParameter("@POVendorID", SqlDbType.Int);
parPOVendorID.Value = POVendorID;
cmd.Parameters.Add(parPOVendorID);
try
{
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception exp)
{
throw new Exception(exp.Message.ToString());
}
finally
{
cmd.Dispose();
con.Close();
}
}
存储过程代码:
ALTER PROCEDURE [dbo].[uspAddNewPOrder]
(
@PODate datetime = null,
@POVendorID int= null
)
AS
BEGIN
INSERT INTO PurchaseOrders.[dbo].[tblPurchaseOrders]
(
PODate,
POVendorID
)
VALUES
(
@PODate,
@POVendorID
)
END