問題仍然存在,現附上我的刪除代碼及錯誤圖片.
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
private void tsbDelete_Click(object sender, EventArgs e)
{
if (dgvQuotationList.Rows.Count == 0)
{
MessageBox.Show("沒有可刪除的記錄!", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (DialogResult.No == MessageBox.Show("确定要刪除料號為[ " + tbPartID.Text.Trim() + " ]的料件單价資料嗎?", "詢問", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
{
return;
}
string strSupplierID = tbSupplierID.Text.Trim();
string strPartID = tbPartID.Text.Trim();
string strMsg = "";
SqlCommand cmd = new SqlCommand();
try
{
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
cmd.Connection = conn;
cmd.CommandText = "Quotation_Delete";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@supplierID", SqlDbType.VarChar, 5);
cmd.Parameters.Add("@partID", SqlDbType.VarChar, 18);
cmd.Parameters.Add("@errorMsg", SqlDbType.VarChar, 200);
cmd.Parameters["@supplierID"].Value = strSupplierID;
cmd.Parameters["@partID"].Value = strPartID;
cmd.Parameters["@errorMsg"].Direction = ParameterDirection.Output;
if (cmd.ExecuteNonQuery() >0)
{
bsQuotationList.RemoveCurrent();
bsQuotationList.EndEdit();
currentState = state.Browse;
ctlState();
}
}
catch
{
strMsg = cmd.Parameters["@errorMsg"].Value.ToString().Trim();
MessageBox.Show(strMsg, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (conn.State != ConnectionState.Closed)
{
conn.Close();
}
}
}