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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:36:15+00:00 2026-06-14T12:36:15+00:00

I am trying to work out SQL code in VB but I am having

  • 0

I am trying to work out SQL code in VB but I am having problems I have a simple database with the table admin with the columns UserName and Password.

I want to be able to read data from a text box and then input it into a SQL string… the SQL string works (I’ve tested it) and I can get it to output with a simple SELECT statement but I can’t seem to get the SQL to read my Parameter.

Help?

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Call Password_Check(txtTestInput.Text)
End Sub

Public Sub Password_Check(ByVal Answer As String)

    Dim con As New SqlConnection
    Dim cmd As New SqlCommand
    Dim parameter As New SqlParameter("@Username", Answer)
    Try

        con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("Database1ConnectionString1").ConnectionString
        con.Open()
        cmd.Connection = con
        cmd.CommandText = " SELECT Password FROM Admin WHERE (UserName = @Username)"
        cmd.Parameters.Add(parameter)
        Dim lrd As SqlDataReader = cmd.ExecuteReader()

        While lrd.Read()
            Dim sothing As String

            sothing = lrd("Password").ToString
            If lrd("Password").ToString = txtPassword.Text Then
                lblTestData.Text = "passwordSuccess"
            ElseIf lrd("Password").ToString <> txtPassword.Text Then
                lblTestData.Text = "passwordFail...:("
            End If
        End While

    Catch ex As Exception
        lblTestData.Text = "Error while retrieving records on table..." & ex.Message
    Finally
        con.Close()
    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-06-14T12:36:17+00:00Added an answer on June 14, 2026 at 12:36 pm

    in your code above:
    –> Dim parameter As New SqlParameter("@Username", Answer)

    Can I suggest two options:

    Dim parameter As New SqlParameter("@Username", sqldbtype.nvarchar)
    
    parameter.value = Answer
    

    or

    cmd.CommandText = string.format("SELECT Password FROM Admin WHERE (UserName = {0})", Answer)
    

    Full Code:

    Public Sub Password_Check(ByVal Answer As String)
    
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        Dim parameter As New SqlParameter("@Username", SqlDbType.NVarChar)
        parameter.Value = Answer
        Try
    
            con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("Database1ConnectionString1").ConnectionString
            con.Open()
            cmd.Connection = con
            cmd.CommandText = "SELECT Password FROM Admin WHERE (UserName = @Username)"
            cmd.Parameters.Add(parameter)
            Dim lrd As SqlDataReader = cmd.ExecuteReader()
    
            While lrd.Read()
                Dim sothing As String
    
                sothing = lrd("Password").ToString
                If lrd("Password").ToString = txtPassword.Text Then
                    lblTestData.Text = "passwordSuccess"
                ElseIf lrd("Password").ToString <> txtPassword.Text Then
                    lblTestData.Text = "passwordFail...:("
                End If
            End While
    
        Catch ex As Exception
            lblTestData.Text = "Error while retrieving records on table..." & ex.Message
        Finally
            con.Close()
        End Try
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to work out how to do a single SQL query which inserts
I am trying work out with MERGE statment to Insert / Update Dimension Table
I am trying to work out the best practice for my problem. I have
I have what seems to be a simple question but its killing me trying
I'm sure this must be something simple, but I can't quite work out what's
Right I have been trying to work out how to compare a given postcode
All, I have been trying to work out how to select say 15 tickets
I'm trying to work out how to validate a user in my application but
Im trying to work out how to get the value from one setting in
I trying to work out what regex will match filenames in quotes. Eg. blah

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.