Results 1 to 4 of 4

Thread: assigning a variable a value from a sql query

  1. #1
    lional is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2012
    Posts
    16
    Reputation
    16

    assigning a variable a value from a sql query

    Hi
    I am trying to query a MSSQL table and pull all the fields from the database and then assign them to the text fields on the form.
    What I am struggling with is how I would assign the text box the value of the database table field.

    Thanks

    Lional

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,339
    Reputation
    1543
    Are you retrieving one record or multiple records? If it's multiple records, do you want to display all of them at once or just one at a time?

  3. #3
    lional is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2012
    Posts
    16
    Reputation
    16
    I am retrieving one record. The record has about 50 fields and each field is assigned to a seperate variable

    Thanks

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,339
    Reputation
    1543
    Then use a SqlCommand, call ExecuteReader to create a SqlDataReader and read each field individually and assign it to the appropriate property of the appropriate control. For an example of using a data reader, amongst others, check out this thread:

    Retrieving and Saving Data in Databases

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking