I have two tables called payment and appointment with relationship with each other using appointmentid. For my current codes, it only insert value into payment table. What I would like to achieve is that if I key in values in the form including the appointmentid and then click submit, the appointmentid that i have just entered, will also updates the record of that appointment table aStatus either to completed or waiting. For my aStatus combobox, i populate it with waiting and completed in the item property.Currently my codes can only insert into the payment table. aStatus is in at another table which is appointment table.
This is my insert of dropdownlist code for aStatus. I want it to update aStatus of appointment table thought. So how do I combine this code with my bottom codes in one button? this code will update aStatus in appointment table and the codes at bottom will insert value at payment table.
string value = cbaStatus.SelectedItem == null ? "waiting" : cbaStatus.SelectedItem.ToString();
updateCmd.Parameters.AddWithValue("@cbaStatus", value);
My form
My tables and relationship
Error following steve codes
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;
}