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 6707193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:36:38+00:00 2026-05-26T07:36:38+00:00

I am getting an exception when I run the below VB.NET code to validate

  • 0

I am getting an exception when I run the below VB.NET code to validate a user..The exception says that “Incorrect syntax near variable user”

Can anyone tell me where am I going wrong ?

      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    If TextBox1.Text.Trim().Length = 0 Or TextBox2.Text.Trim().Length = 0 Then
        MsgBox("Enter a user id and password")
        Return 'Terminate this method
    End If

    Dim myconnection As SqlConnection
    Dim mycommand As SqlCommand
    Dim dr As SqlDataReader
    Dim userid = TextBox1.Text
    Dim password = TextBox2.Text

    Try
        myconnection = New SqlConnection("server=PARTH- PC\SQLEXPRESS;uid=sa;pwd=parth;database=fcrit")

        myconnection.Open()
        mycommand = New SqlCommand("select * from user where [user id]=@userid and [password]=@password", myconnection)
        mycommand.Parameters.Add("@userid", SqlDbType.VarChar, 30).Value = userid
        mycommand.Parameters.Add("@password", SqlDbType.VarChar, 30).Value = password

        'mycommand = New SqlCommand("select * from user where user id='" & TextBox1.Text & "' and password='" & TextBox2.Text & "'", myconnection)
        dr = mycommand.ExecuteReader()

        If (dr IsNot Nothing) Then
            If (dr.Read()) Then
                MsgBox("User is authenticated")
                Form2.Show()
            Else
                MsgBox("Please enter correct username and password")
            End If
        End If
        myconnection.Close()
    Catch ex As Exception
        Throw

    Finally
    End Try
  End Sub
  • 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-05-26T07:36:38+00:00Added an answer on May 26, 2026 at 7:36 am

    User is a reserved word in SQL Server.

    Put brackets around the table name:

    mycommand = New SqlCommand("select * from [user] where [user id]=@userid and [password]=@password", myconnection)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting an exception when trying to run the below code in vb.net
I am getting the below exception when I run my ASP.NET/C#/SQL project on an
I'm getting the following exception for the code included below that. This works fine
This is the exception that I am getting when I run my application with
In one of our application im getting an exception that i can not seem
I keep getting a invalid identifier exception when I try to run the below
I'm getting the following exception when I run my application in Release mode from
i'm getting exception on Transformer transformer = tFactory.newTransformer(StreamXSL); but the error below is not
(the example code below is self-contained and runnable, you can try it, it won't
I'm getting the exception listed below when looking at the MainPage.xaml of a newly

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.