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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:01:17+00:00 2026-05-27T21:01:17+00:00

How may I correctly assign textboxes, dropdownlists & labels to appropriate fields, on successful

  • 0

How may I correctly assign textboxes, dropdownlists & labels to appropriate fields, on successful retrieval of records via a SQL statement? I have 4 tables & therefore, the assigned data don’t match the controls. (VS2008)

I have the following:

myCmd.CommandText = "SELECT pc.product_category_id, pc.product_category_name, pi.product_image_id, pi.product_image_filename, qr.qrcode_id, qr.qrcode_image_filename, p.product_author FROM Product AS p INNER JOIN ProductCategory AS pc ON p.product_category_id = pc.product_category_id INNER JOIN ProductImage AS pi ON p.product_image_id = pi.product_image_id INNER JOIN  QRCode AS qr ON p.qrcode_id = qr.qrcode_id WHERE p.product_id = '" & DropDownList2.Text & "'"

myCmd.Parameters.Add(New SqlParameter("@product_id", (DropDownList2.Text)))
myConn.Open()
'run the query and obtain a reader to get the results 
dtrReader = myCmd.ExecuteReader()

'check if there are results
If (dtrReader.Read()) Then
   'populate the values of the controls
   lblProductID2.Text = dtrReader(0)
   txtProductName2.Text = dtrReader(4)
   txtProductTitle2.Text = dtrReader(7)
   txtProductDescription2.Text = dtrReader(8)
   txtProductAuthor2.Text = dtrReader(12)
  • 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-27T21:01:18+00:00Added an answer on May 27, 2026 at 9:01 pm

    There are at least two ways to solve this:

    1) Explicitly use the names of the columns when retrieving from datareader:

    lblProductID2.Text = dtrReader("product_category_id")
    ' etc
    

    2) Cycle through each of the fields in the reader and use a case statement to assign values

    For nI As Integer = 0 To dtrReader.FieldCount - 1
       Select Case dtrReader.GetName(nI).ToLower()
          Case "product_category_id"
             If Not dtrReader.IsDBNull(nI) Then
                 lblProductID2.Text = dtrReader.GetString(nI)
             Else
                 lblProductID2.Text = String.Empty
             End If
    
          ' etc
    
       End Select
    Next
    

    Number 2 is probably slightly better because it makes it easier to test for DBNull values in the returned data:

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

Sidebar

Related Questions

This may not be the correct way to use controllers, but I did notice
This may not really sound hard to do but it is currently killing me.
This may be super easy to solve but I can't find the correct google
I'm currently struggling with this Collection was modified; enumeration operation may not execute issue.
Currently I use a HashMap<Class, Set<Entry>> , which may contain several millions of short-lived
I may be waaaay off, or else really close. Either way, I'm currently SOL.
We have some stuff that may be exported into various formats. Currently we have
Hey all, title may be abit misleading but i didnt know the correct way
May be my title is not clear. I am looking for some kind of
May be I am getting old, but I can't find it...

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.