1
我有兩個表叫付款和約會關係彼此使用約會。對於我目前的代碼,它只會將值插入付款表。我想實現的是,如果我輸入包含委任名稱的表單中的值,然後單擊提交,那麼我剛輸入的任務也會更新該預約表aStatus的記錄,以完成或等待。對於我的aStatus組合框,我用等待填充它並在項目屬性中完成。目前我的代碼只能插入付款表中。 aStatus在另一張桌子是預約表。如何將值插入到表中並使用一個按鈕更新另一個表中的值?
這是我爲aStatus插入dropdownlist代碼。我想要它更新預約表思想的一個狀態。那麼如何將此代碼與我的底部代碼結合在一個按鈕中?此代碼將更新預約表中的狀態,底部的代碼將在支付表中插入值。
string value = cbaStatus.SelectedItem == null ? "waiting" : cbaStatus.SelectedItem.ToString();
updateCmd.Parameters.AddWithValue("@cbaStatus", value);
我的形式
我的表和關係
以下錯誤史蒂夫代碼
private void btnSubmit_Click(object sender, EventArgs e)
{
int result = AddPaymentRecord();
if (result > 0)
{
MessageBox.Show("Insert Successful");
txtamount.Clear();
txtamountPaid.Clear();
txtappointmentID.Clear();
txtamount.Focus();
}
else
{
MessageBox.Show("Insert Fail");
txtamount.Clear();
txtamountPaid.Clear();
txtappointmentID.Clear();
txtamount.Focus();
}
}
private int AddPaymentRecord()
{
int result = 0;
string strConnectionString = ConfigurationManager.ConnectionStrings["sacpConnection"].ConnectionString;
SqlConnection myConnect = new SqlConnection(strConnectionString);
String strCommandText = "INSERT PAYMENT(amount, amountPaid, paymentDate, paymentType, appointmentID) "
+ " VALUES (@Newamount, @NewamountPaid,@NewpaymentDate, @NewpaymentType, @NewappointmentID)";
SqlCommand updateCmd = new SqlCommand(strCommandText, myConnect);
updateCmd.Parameters.AddWithValue("@Newamount", txtamount.Text);
updateCmd.Parameters.AddWithValue("@NewamountPaid", txtamountPaid.Text);
updateCmd.Parameters.AddWithValue("@NewpaymentDate", dtppaymentDate.Value);
if (rbCash.Checked)
updateCmd.Parameters.AddWithValue("@NewpaymentType", "Cash");
else
updateCmd.Parameters.AddWithValue("@NewpaymentType", "Credit Card");
updateCmd.Parameters.AddWithValue("@NewappointmentID", txtappointmentID.Text);
myConnect.Open();
result = updateCmd.ExecuteNonQuery();
myConnect.Close();
return result;
}
我得到錯誤(第3圖像)@Steve – Pony
@Jordjmax在某些時候,你必須採取所有權和了解您爲學校項目轉入的代碼。 –
opps該約會有一個拼寫錯誤,我認爲。好吧,哈哈。 @凱斯佩恩 – Pony