Skip to content

Not sure where to post this. (Query string result)

David

Asked Aug 17, 2006, 9:28 AM EDT1 answer
Share
LinkedInX
Hi,
Im writing an ASP.Net web form with C# code behinds. (.net 2.0 / MSVisualStudio 2005 Pro)
I have a sql string ....

string strSQL = "SELECT Email FROM form WHERE Email = ('" + EmailAddressTxtBox.Text + "')";

Which Im trying to compare the result of to see if the email exists in my DB.

OdbcCommand myODBCCommand = new OdbcCommand(strSQL, conn);

conn.Open();

myODBCCommand.ExecuteNonQuery();

string EmailResult =  ???????????????  ;

if (EmailResult == " ")

EmailNullLbl.Text = "Email address does not exist.";

else

EmailNullLbl.Text = " ";

Basically, if there is a result from the query , that means the email exists in the DB and if there is no result in the query, the email does not exist in the DB. If it doesn't exist in the DB then I want my label (EmailNullLbl.Text) to say the email does not exist.

My question is the section with the question marks in red above. I know the query works because if the email does exist , it displays the whole row on my page via a details view data control. But what would the result of my query be stored under? What is it called?

Please and thanks..for any help.
Regards,
David

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    ExecuteNonQuery() returns no information about SELECT query.

    First, if you are only interested on whether the record exists, you better use the COUNT function like this:

    string strSQL = "SELECT COUNT(Email) FROM form WHERE Email = ('" + EmailAddressTxtBox.Text + "')";

    Then, use ExecuteScalar() to get the number of record found:

    int count = (int)myODBCCommand.ExecuteScalar();

    Prompt the error message if count equals 0.

    0