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

  • Home
  • SEARCH
  • 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 7781873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:21:50+00:00 2026-06-01T19:21:50+00:00

This is my first attempt at writing a program that accesses a database from

  • 0

This is my first attempt at writing a program that accesses a database from scratch, rather than simply modifying my company’s existing programs. It’s also my first time using VB.Net 2010, as our other programs are written in VB6 and VB.NET 2003. We’re using SQL Server 2000 but should be upgrading to 2008 soon, if that’s relevant.

I can successfully connect to the database and pull data via query and assign, for instance, the results to a combobox, such as here:

Private Sub PopulateCustomers()
    Dim conn As New SqlConnection()
    Dim SQLQuery As New SqlCommand
    Dim daCustomers As New SqlDataAdapter
    Dim dsCustomers As New DataSet

    conn = GetConnect()
    Try
        SQLQuery = conn.CreateCommand
        SQLQuery.CommandText = "SELECT Customer_Name, Customer_ID FROM Customer_Information ORDER BY Customer_Name"
        daCustomers.SelectCommand = SQLQuery
        daCustomers.Fill(dsCustomers, "Customer_Information")

        With cboCustomer
            .DataSource = dsCustomers.Tables("Customer_Information")
            .DisplayMember = "Customer_Name"
            .ValueMember = "Customer_ID"
            .SelectedIndex = -1
        End With

    Catch ex As Exception
        MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
    End Try

    conn.Close()

End Sub

I also have no problem executing a query that pulls a single field and assigns it to a variable using ExecuteScalar. What I haven’t managed to figure out how to do (and can’t seem to hit upon the right combination of search terms to find it elsewhere) is how to execute a query that will return a single row and then set various fields within that row to individual variables.

In case it’s relevant, here is the GetConnect function referenced in the above code:

Public Function GetConnect()
     conn = New SqlConnection("Data Source=<SERVERNAME>;Initial Catalog=<DBNAME>;User Id=" & Username & ";Password=" & Password & ";")
     Return conn
End Function

How do I execute a query so as to assign each field of the returned row to individual variables?

  • 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-01T19:21:52+00:00Added an answer on June 1, 2026 at 7:21 pm

    Like @Roland Shaw, I’d go down the datareader route but an other way.

    would be to loop through

    dsCustomers.Tables("Customer_Information").Rows
    

    Don’t forget to check to see if there are any rows in there.

    Google VB.Net and DataRow for more info.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an application using DDD techniques. This is my first attempt at a
Because this is my first attempt at an extension method that seems quite useful
This is my first ever attempt at writing a recursive function in c. The
This is my first attempt at writing a QT app, and I'm just trying
This is my first attempt to build an ASP.NET server control. Writing the control
This is my first-attempt at writing anything even slightly complicated in C++, I'm attempting
this if my first attempt at using streaming for WCF, and I am struggling
This is my first attempt to create a GUI in MATLAB. I haven't been
this is my first attempt at a responsive design so excuse me if this
This is pretty strange (admitedly, this is my first attempt with python / sqlite),

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.