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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:28:49+00:00 2026-06-13T12:28:49+00:00

Okay, I am building a VB.NET system but I’m having troubles in catching an

  • 0

Okay, I am building a VB.NET system but I’m having troubles in catching an SQL exception in some parts of my code. In short, I am using a SELECT sql query to retrieve a particular record and I want to determine whether a record exist in a MSAccess database so that I don’t retrieve 0 rows. 0 rows will lead to an exception during printing to a TextField. The following is a sample code I’m working on:

    If txSearch.Text = "" Then
        MsgBox("Please type the user id or use the barcode reader to scan",     MsgBoxStyle.OkOnly, "Search Field Empty")
    End If

    'ElseIf txSearch.Text != "" Then
    If txSearch.Text <> "" Then
        Dim con As New OleDb.OleDbConnection
        Dim dbProvider As String
        Dim dbSource As String
        Dim ds As New DataSet
        Dim dt As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim de As OleDb.OleDbDataAdapter
        Dim sql As String
        Dim sql1 As String
        Dim temp_num As Integer
        Dim cmd As New OleDb.OleDbCommand

        dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
        dbSource = "Data Source = new.mdb"

        con.ConnectionString = dbProvider & dbSource

        con.Open()

        Dim search As String
        search = txSearch.Text
        MessageBox.Show("You are going to search for " + search + ". Click OK to continue.")

        sql = "SELECT * FROM Student_Details WHERE Admin_No = '" & txSearch.Text & "'"

        sql1 = "SELECT * FROM Laptop_Details WHERE Admin_No = '" & txSearch.Text & "'"

        da = New OleDb.OleDbDataAdapter(sql, con)

        de = New OleDb.OleDbDataAdapter(sql1, con)

        'Dim check As Integer = sql.
        'If check > 0 Then

        'da.SelectCommand = cmd
        ds = New DataSet("Student_Details")
        da.Fill(ds, "Student_Details")
        dt = New DataSet("Laptop_Details")
        de.Fill(dt, "Laptop_Details")
        'con.Close()

        'If sql <> "" And sql1 <> "" Then
        'If ds.Equals(1) And ds.Equals(1) Then
        txAdminNO.Text = ds.Tables("Student_Details").Rows(0).Item(0)
        txName.Text = ds.Tables("Student_Details").Rows(0).Item(1)
        txProgramme.Text = ds.Tables("Student_Details").Rows(0).Item(2)
        cmbSStatus.SelectedText = ds.Tables("Student_Details").Rows(0).Item(3)
        txSerial.Text = dt.Tables("Laptop_Details").Rows(0).Item(1)
        txModel.Text = dt.Tables("Laptop_Details").Rows(0).Item(2)

        Dim com As New OleDb.OleDbCommand(sql, con)
        Dim com1 As New OleDb.OleDbCommand(sql1, con)

        Try

            temp_num = com.ExecuteNonQuery
            temp_num = com1.ExecuteNonQuery

        Catch ex As IndexOutOfRangeException
            Trace.WriteLine(ex.ToString)

        End Try

        con.Close()
        'End If
        'End If
    End If
  • 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-13T12:28:50+00:00Added an answer on June 13, 2026 at 12:28 pm

    Try something like this:

     if ds.Tables("Student_Details").Rows.Count > 0  
        txAdminNO.Text = ds.Tables("Student_Details").Rows(0).Item(0)
        txName.Text = ds.Tables("Student_Details").Rows(0).Item(1)
        txProgramme.Text = ds.Tables("Student_Details").Rows(0).Item(2)
        cmbSStatus.SelectedText = ds.Tables("Student_Details").Rows(0).Item(3)
    
     End if
    
     if ds.Tables("Laptop_Details").Rows.Count > 0
        txSerial.Text = dt.Tables("Laptop_Details").Rows(0).Item(1)
        txModel.Text = dt.Tables("Laptop_Details").Rows(0).Item(2)
     End if
    

    To help you with your comment I would do it like that:

     if ds.Tables("Student_Details").Rows.Count > 0 And ds.Tables("Laptop_Details").Rows.Count > 0
        txAdminNO.Text = ds.Tables("Student_Details").Rows(0).Item(0)
        txName.Text = ds.Tables("Student_Details").Rows(0).Item(1)
        txProgramme.Text = ds.Tables("Student_Details").Rows(0).Item(2)
        cmbSStatus.SelectedText = ds.Tables("Student_Details").Rows(0).Item(3)
        txSerial.Text = dt.Tables("Laptop_Details").Rows(0).Item(1)
        txModel.Text = dt.Tables("Laptop_Details").Rows(0).Item(2)
     else
      MsgBox("The user with id "+txSearch.Text+" does not exist") 
     end if
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I feel a bit foolish for having to ask this but I guess
Okay, I'm having some serious issues here. I'm new to this site, and new
Okay, I'm building a page in a CF environment. I'm testing in chrome/FF &
okay, i'm setting up a multi-user chat system. i have a messages table, that
Okay, this is probably a very basic question; but, I'm just getting back in
Building a Windows 8 app, developers can choose HTML/JavaScript, XAML/.Net (C#/VB), and XAML/C++. I
Okay so I'm building a CSS drop down menu similar to that on ESPN's
I am building a CMS for a client, and I needed some inspiration from
Okay, So I am building an ajax based game. Anyway it is multiplayer, connects
Edit: Here's a Fiddle of the situation. Okay, so I'm building a web page,

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.