Click here to Skip to main content
15,509,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 29-Jul-18 20:09pm
Comments
Manish K. Agarwal 30-Jul-18 0:38am    
Please see if your LEDGER table has the DATA corresponding to the filter which you are passing in SELECT
Member 13854008 30-Jul-18 0:51am    
tankuu very much sir...i got it with ur help

1 solution

OP posted:
Quote:
tankuu very much sir...i got it with ur help

Answered only to remove from unanswered queue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900