Click here to Skip to main content
15,891,908 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
private void btnCalc_Click(object sender, EventArgs e)
       {
           label3.Visible = true;
           label4.Visible = true;
           try
           {

               con.Open();
               SqlDataAdapter da = new SqlDataAdapter("select * from pppp where res='" + this.label4.Text+ "'", con);
               DataSet ds = new DataSet();
               da.Fill(ds, "cal");
               DataView vd = new DataView(ds.Tables["cal"]);
               label4.Text = vd[0]["calr"].ToString();
               con.Close();
           }
           catch (Exception p)
           {
               MessageBox.Show(p.Message);
           }

       }
Posted
Updated 7-Sep-12 7:03am
v3
Comments
[no name] 7-Sep-12 12:23pm    
Probably, because you are taking a string, converting it to an int, then passing it as a string through your SQL when your id is probably an int.
Ashraff Ali Wahab 7-Sep-12 12:27pm    
Please print the exception and post it instead of leaving emplty exception block ,this will solve half your problem.
Gilbertinino 7-Sep-12 12:36pm    
how can i solve it?
[no name] 7-Sep-12 12:39pm    
I know you did not ask me but try: SqlDataAdapter da = new SqlDataAdapter("select * from pppp where id=" + int.Parse(lblId.Text), con);
Ashraff Ali Wahab 7-Sep-12 12:44pm    
Gilbertino : What I meant is the exception will show what is the issue with the code.Anyway Wes updated the code ,if it still not works for you ,paste the exception you are getting.

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