After the procedure Obtain_Property_ID has ran, the Prop_ID suppose to be some value from 1 to 5, but instead it remains a 0.
string Prop_ID = "0";
Obtain_Property_ID(Prop_Name, Prop_ID);
R1.Reservation_Number.Text = "R-" + Prop_ID; <<--- Suppose to be a 3, but it has a value of 0.
string Prop_ID = "0";
Obtain_Property_ID(Prop_Name, Prop_ID);
R1.Reservation_Number.Text = "R-" + Prop_ID; <<--- Suppose to be a 3, but it has a value of 0.
C#:
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
string Apartment_Status;
DateTime Date_Reserved = DateTime.Today;
MessageBox.Show("Date_Reserved = " + Date_Reserved);
object value = this.dataGridView2.CurrentRow.Cells[7].Value.ToString();
Apartment_Status = value.ToString();
MessageBox.Show("Apartment_Status = " + Apartment_Status);
switch (Apartment_Status)
{
case "Reserved":
Reservation2 R2 = new Reservation2();
R2.Show();
break;
case "Vacant":
Reservation1 R1 = new Reservation1();
R1.Property_Name.Text = this.dataGridView2.CurrentRow.Cells[0].Value.ToString();
string Prop_Name = R1.Property_Name.Text;
string Prop_ID = "0";
Obtain_Property_ID(Prop_Name, Prop_ID);
R1.Reservation_Number.Text = "R-" + Prop_ID;
R1.Unit_Number.Text = this.dataGridView2.CurrentRow.Cells[1].Value.ToString();
R1.Date_Reserved.Text = Date_Reserved.ToString();
R1.Lease_Months.Text = "6";
R1.Reservation_Cancelled.Text = "No";
R1.Show();
break;
default:
break;
}
void Obtain_Property_ID(string Prop_Name, string Prop_ID)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["Apartment_Management.Properties.Settings.AMS_2007ConnectionString"].ToString();
con.Open();
MessageBox.Show("Obtain_Property_ID procedure. Prop_Name = " + Prop_Name);
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "SELECT Property_ID FROM Property WHERE Property_Name = '" + Prop_Name + "' ";
cmd.Connection = con;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Prop_ID = (string)ds.Tables[0].Rows[0].ItemArray[0];
MessageBox.Show("Property_ID = " + Prop_ID); //This showed a 3, and it is correct
//The MessageBox did showed a correct number of 3, but
//after it exit the procedure, the variable Prop_ID no longer has value of 3
// but a 0.
}
}