Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005 C#
 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 7-Sep-12 7:20am
Edited 7-Sep-12 8:03am
v3
Comments
Wes Aday at 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 at 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 at 7-Sep-12 12:36pm
   
how can i solve it?
Wes Aday at 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 at 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.
Gilbertinino at 7-Sep-12 12:50pm
   
parameters were not supplied for the function pppp
Ashraff Ali Wahab at 7-Sep-12 14:04pm
   
Please check you database.You may be having a function which is pppp and also a table pppp.
__TR__ at 7-Sep-12 12:48pm
   
This may not have anything to do with the issue you are facing, but i thought will mention it anyway. I noticed that you are first closing the connection and then opening it. This is incorrect. You need to first open the connection to database and once you retrieve the data from database you need to close it at the end.

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

  Print Answers RSS
0 OriginalGriff 381
1 Praneet Nadkar 237
2 Marcin Kozub 225
3 Sergey Alexandrovich Kryukov 200
4 Shweta N Mishra 161
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 7 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100