see07 Posted July 19, 2004 Posted July 19, 2004 Hello: I�m trying to obtain quantity of records in a table that meet certain criteria. When I run the project I�m obtaining an error: �Specified conversion isn�t valid�, this in line where I put value of command to TextBox2. What is bad in this script? I�ll thank your help. A.L. private void Button3_Click(object sender, System.EventArgs e) { sqlConnection1.Open(); SqlCommand comandante = new SqlCommand("Comando",sqlConnection1); comandante.CommandType = CommandType.Text; comandante.CommandText = "SELECT count(*) FROM PETICION where(id_status = 1)"; TextBox2.Text = (string)(comandante.ExecuteScalar()); sqlConnection1.Close(); } Quote
Arch4ngel Posted July 19, 2004 Posted July 19, 2004 Check that commandante.ExecuteScalar() doesn't return a null pointer. If it return null... no cast can be made. Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Administrators PlausiblyDamp Posted July 19, 2004 Administrators Posted July 19, 2004 Try TextBox2.Text=comandante.ExecuteScalar().ToString(); Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
see07 Posted July 19, 2004 Author Posted July 19, 2004 Thanks you PlausibleDamp, your suggestion is orking very well, you re so gentle ith me, again thanks you..... Thanks you too Arch4angel.... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.