Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9193047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:04:08+00:00 2026-06-17T21:04:08+00:00

I’m trying to compare a string (network ID) and using a SQL Like command,

  • 0

I’m trying to compare a string (network ID) and using a SQL Like command, return the numbers of rows affected (if the user name was found or not) however in my code I’m always getting ” -1 ” which i can not find why, the username is correct and found in the SQL table by running a query in SQL Server Mgt.

Try
        Dim Con As New SqlConnection
        Con.ConnectionString = "Data Source=WCRDUSMJEMPR9\SQLEXPRESS;Initial Catalog=MicroDB;Integrated Security=True"
        Con.Open()
        Dim SQL2 As String
        SQL2 = "SELECT * from MicroDB_Users WHERE Users LIKE '+@Usercheck+'"
        Dim cmd2 As New SqlCommand(SQL2, Con)
        cmd2.Parameters.AddWithValue("@Usercheck", TextBox1.Text)
        Dim obj2 = cmd2.ExecuteNonQuery
        Con.Close()
        If obj2 > 0 Then
            MsgBox(obj2)
            Response.Redirect("~\ControlCharts\AddData_Control.aspx")
            Label7_Control.Visible = False
        Else
            MsgBox(obj2)
            Label7_Control.Text = ("You are not authorized to Add Data")
            Label7_Control.Visible = True
        End If
    Catch ex As Exception
        MsgBox(Err.Description)

As you can see, i;m using a IF to compare if the user was found ( 1 row affected) or if it was not found ( 0 rows affected).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:04:09+00:00Added an answer on June 17, 2026 at 9:04 pm

    ExecuteNonQuery is used for insert,update or delete queries only. So you either have to use COUNT in your query and use ExecuteScalar or use ExecuteReader and the reader’s HasRows property.

    Using var reader = cmd2.ExecuteReader()
        If reader.HasRows Then
            ' ...
        Else
            ' ...
        End If
    End Using
    

    ExecuteNonQuery:

    For UPDATE, INSERT, and DELETE statements, the return value is the
    number of rows affected by the command. When a trigger exists on a
    table being inserted or updated, the return value includes the number
    of rows affected by both the insert or update operation and the number
    of rows affected by the trigger or triggers. For all other types of
    statements, the return value is -1.
    If a rollback occurs, the return
    value is also -1.

    Update: Apart from that you’re using the LIKE operator and the parameter incorrectly. Instead of

    SQL2 = "SELECT * from MicroDB_Users WHERE Users LIKE '+@Usercheck+'"
    cmd2.Parameters.AddWithValue("@Usercheck", TextBox1.Text)
    

    use this approach

    SQL2 = "SELECT * from MicroDB_Users WHERE Users LIKE @Usercheck"
    cmd2.Parameters.AddWithValue("@Usercheck", string.Format("%{0}%", TextBox1.Text))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.