我想訪問全局變量「i」的前一個值。 這是我的代碼。我如何訪問變量的前一個值?
int i = 0;
private void btnSave_Click(object sender, EventArgs e)
{
if (con.State == ConnectionState.Open) { con.Close(); }
try
{
con.Open();
i++;
//int i2=i-1;
String s = "insert into Add_Information values('"+i +"','"+ txtCompanyName.Text + "','" + txtOffAddress1.Text + "','" + txtOffAddress2.Text + "','" + txtCityAndPin.Text + "','" + txtContactPersonName.Text + "','" + txtDesignation.Text + "'," + txtOffPhoneNo.Text + "," + txtFaxNo.Text + "," + txtMobileNo.Text + ",'" + txtOfficialEmailId.Text + "','" + txtPersonalEmailId.Text + "','" + txtAlternativeContactPersonName.Text + "','" + txtWebsite.Text + "','" + txtClientClassification.Text + "','" + txtDetails.Text + "','" + txtGroup.Text + "','" + pictureBox1.Image + "')";
SqlCommand cmd = new SqlCommand(s, con);
if (cmd.ExecuteNonQuery() >= 1)
{
MessageBox.Show("Succesfully Updated !!");
}
con.Close();
}
catch (Exception ex)
{
/*if(txtFaxNo.Text==""||txtMobileNo.Text==""||txtOffPhoneNo.Text=="")
{
MessageBox.Show("Fax No,Mobile No,Office No should not be character");
}*/
con.Close();
MessageBox.Show(ex.Message);
}
我要訪問我的以前的值存儲在數據表中Add_Information即使在目前的形式被關閉