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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:18:48+00:00 2026-05-31T23:18:48+00:00

I’m trying to retrieve record data from an MS-Access database and store it into

  • 0

I’m trying to retrieve record data from an MS-Access database and store it into a variable.

I’m using this SQL command to query the database:

Dim cmdRead As OleDbCommand = New OleDbCommand("SELECT UserID FROM [User] where Username=?", conn)

How do I do it in VB.NET to read data from the UserID column (in the db) and store it into a variable in VB.NET?

What I basically want to do is to retrieve the UserID so that I can then retrieve the Name and Surname of the user from the same table.

Note: I’m using ASP.NET with Web Develop 2003 and an MS-Access 2003 db.

This is the full code:

  Imports System.Data.OleDb

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub btnLogin_Click(sender As Object, e As System.EventArgs) Handles btnLogin.Click

        Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Brian\Documents\Visual Studio 2010\WebSites\WebSite3\db.mdb;")


        Dim cmd As OleDbCommand = New OleDbCommand("SELECT Username, Password FROM [User] where Username=? and Password=?", conn)

        cmd.Parameters.AddWithValue("@Username", txtUsername.Text)
        cmd.Parameters.AddWithValue("@Password", txtPassword.Text)


        Try
            conn.Open()
            Dim read As OleDbDataReader = cmd.ExecuteReader()
            If read.HasRows Then
                While read.Read()
                    If txtUsername.Text = read.Item("username").ToString And txtPassword.Text = read.Item("password").ToString Then

                        Dim tID As Long = read.Item("UserID").ToString
                        Dim tName As String = read.Item("CustomerName").ToString
                        Dim tSurname As String = read.Item("CustomerSurname").ToString

                        lblLogged.Text = lblLogged.Text + tName + tSurname

                        lblLogged.Visible = True
                    End If
                End While
            Else
                lblLogged.Text = "Login unsuccessful"
            End If

            read.Close()
        Catch ex As Exception
            Response.Write(ex.Message())

        Finally
            conn.Close()
        End Try


    End Sub

End Class
  • 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-31T23:18:49+00:00Added an answer on May 31, 2026 at 11:18 pm

    This should go in your Try block

    conn.Open()             
    Dim read As OleDbDataReader = cmd.ExecuteReader()             
    If read.HasRows Then              
        While read.Read()             
            If txtUsername.Text = read.Item("username").ToString And txtPassword.Text = read.Item("password").ToString Then                
                Dim tID as long = read.Item("UserID").ToString
            Else                 
                lblLogged.Text = "Login unsuccessful"             
            End If   
        End While           
    End If   
    

    And in the Finally block

    read.Close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is

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.