this is my code, but it enter else part only.it didn't enter to if part ,i couldn't get the error....
con.Open();
int a1;
a1 = int.Parse(textBox3.Text);
string r2 = textBox2.Text;
string q3 = textBox1.Text;
SqlCommand cmd = new SqlCommand("select * from ledger where year ='" + r2 + "'and purticulars ='" + q3 + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
int ti = Convert.ToInt32(dt.Rows[0]["credit"].ToString());
int q = ti - a1;
SqlCommand cmd3 = new SqlCommand("update ledger set credit ='" + q + "' where purticulars='" + q3 + "' and year='" + r2 + "'", con);
cmd3.ExecuteNonQuery();
}
else
{
MessageBox.Show("error");
}
con.Close();
What I have tried:
con.Open();
int a1;
a1 = int.Parse(textBox3.Text);
string r2 = textBox2.Text;
string q3 = textBox1.Text;
SqlCommand cmd = new SqlCommand("select * from ledger where year ='" + r2 + "'and purticulars ='" + q3 + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
int ti = Convert.ToInt32(dt.Rows[0]["credit"].ToString());
int q = ti - a1;
SqlCommand cmd3 = new SqlCommand("update ledger set credit ='" + q + "' where purticulars='" + q3 + "' and year='" + r2 + "'", con);
cmd3.ExecuteNonQuery();
}
else
{
MessageBox.Show("error");
}
con.Close();
///it only work the else part