解決以後麻煩告知一下經驗
すばらしいコードを書き出すのは楽しい事です
問題仍未解決﹐現附上部份代碼﹐請大蝦們幫看看
1﹒綁定數据到DGV中的代碼
private void bindingQuotationList(string strSupplierID)
{
if (ds.Tables["QuotationList"] != null)
{
ds.Tables["QuotationList"].Clear();
}
SqlCommand cmdQuotationList = new SqlCommand();
cmdQuotationList.CommandText = "SELECT * FROM [ViewQuotation] WHERE [SupplierID] = @sid ORDER BY [QuotationID]";
cmdQuotationList.CommandType = CommandType.Text;
cmdQuotationList.Parameters.Add(new SqlParameter("@sid", strSupplierID));
cmdQuotationList.Connection = conn;
sdaQuotationList = new SqlDataAdapter(cmdQuotationList);
sdaQuotationList.Fill(ds, "QuotationList");
bsQuotationList.DataSource = ds.Tables["QuotationList"];
dgvQuotationList.DataSource = bsQuotationList;
}
2.執行刪除的代碼﹕
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();
}
}
}
我刚依你的方法做了一个简单的例子,也没有问题,但搞不懂我的程序中为什么会是那样子,我得再试试.