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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:56:24+00:00 2026-05-27T18:56:24+00:00

May i have a working sample on how to retrieve records from a DB

  • 0

May i have a working sample on how to retrieve records from a DB & populate the relevant textboxes after a selection at a dropdownlist. What i have is definitely not working & im working on VS 2008. Can anyone show me the way?

What i have:

    Dim myConn As New SqlConnection
    Dim myCmd As New SqlCommand
    Dim dtrReader As SqlDataReader

    myConn.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
    myCmd = myConn.CreateCommand

    myCmd.CommandText = "SELECT * FROM Product WHERE product_id = '" & DropDownList2.Text & "'"
        'myCmd.CommandType = CommandType.Text

        'populate controls from DB
        'myCmd.Parameters.Add(New SqlParameter("@product_id", a))
        myCmd.Parameters.Add(New SqlParameter("@product_name", (txtProductName2.Text)))
        myCmd.Parameters.Add(New SqlParameter("@product_title", txtProductTitle2.Text))
        myCmd.Parameters.Add(New SqlParameter("@product_desc", txtProductDescription2.Text))
        myCmd.Parameters.Add(New SqlParameter("@product_author", txtProductAuthor2.Text))

        mycmd.Dispose()
        myConn.Close()
        myConn.Dispose()
  • 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-27T18:56:25+00:00Added an answer on May 27, 2026 at 6:56 pm

    The parameters collection of the command is to pass parameters to the query and not fill in variables from a result. First you should do the query and then read the results and fill your controls:

    ' build the query with the product id as paramter
    myCmd.CommandText = "SELECT product_name, product_title, product_desc, product_author FROM Product WHERE product_id = @product_id"
    ' add the parameter so the SqlCommand can build the final query
    myCmd.Parameters.Add(New SqlParameter("@product_id", (DropDownList2.Text)))
    
    ' run the query and obtain a reader to get the results
    Dim reader As SqlDataReader = myCmd.ExecuteReader()
    
    ' check if there are results
    If (reader.Read()) Then
         ' populate the values of the controls
         txtProductName2.Text = reader(0)
         txtProductTitle2.Text = reader(1)
         txtProductDescription2.Text = reader(2)
         txtProductAuthor2.Text = reader(3)
    End If
    

    This is just a quick example and contains no error handling but should work.

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

Sidebar

Related Questions

I'm working in xmldataprovider and we have configuration value source this value may be
At work, we have multiple branches that we may be working on at any
You may have heard of PawSense , a Windows-only utility that prevents keystrokes from
As you may have guessed from the question - I am right at the
NOTE: I'm working in .NET 3.5 here. Let's say I have sample base/child classes
I have developed a sample app, which uses Facebook features, and it is working
You may have seen JavaScript sliders before: http://dev.jquery.com/view/tags/ui/1.5b2/demos/ui.slider.html What I'm envisioning is a circular
You may have noticed that we now show an edit summary on Community Wiki
I have a CSV data file with rows that may have lots of columns
This question may have been asked before, but I had trouble finding an answer,

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.