Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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();

}

Posted

Check that commandante.ExecuteScalar() doesn't return a null pointer.

 

If it return null... no cast can be made.

"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

Posted

Thanks you PlausibleDamp, your suggestion is orking very well, you re so gentle ith me, again thanks you.....

Thanks you too Arch4angel....

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...