Results 1 to 7 of 7

Thread: Read field from database into variable

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    2

    Read field from database into variable

    Hi, I simply wont to read one field in a databasetable into a variable.

    dim text as string
    text = table.field

    How do I do that.
    A beginner

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Read field from database into variable

    I'd recommend reading a tutorial on database access in the first instance.

    Jmcilhinney's code bank article covers all you need to know to get you going.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2010
    Posts
    2

    Re: Read field from database into variable

    This is what I found on the internet but this is not working

    Dim a As String
    a = Me.dataset.tabel.row(1).field(1)

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Read field from database into variable

    Quote Originally Posted by albel View Post
    This is what I found on the internet but this is not working

    Dim a As String
    a = Me.dataset.tabel.row(1).field(1)
    Have you followed the link provided? If you have then you've got the answer, so posting something else that doesn't work is of no value.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Addicted Member
    Join Date
    Oct 2008
    Posts
    152

    Re: Read field from database into variable

    Quote Originally Posted by albel View Post
    This is what I found on the internet but this is not working

    Dim a As String
    a = Me.dataset.tabel.row(1).field(1)
    You do not need to create and fill an entire dataset if all you are returning is a single value. Your using more resources then you need. Follow JMC's advice and also take a look at the command objects executescalar method for returning a single value.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Read field from database into variable

    Quote Originally Posted by Tom.Net View Post
    Follow JMC's advice and also take a look at the command objects executescalar method for returning a single value.
    Which is exactly what the first code example, entitled something like "Getting a single value", in my CodeBank thread does.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Addicted Member
    Join Date
    Oct 2008
    Posts
    152

    Re: Read field from database into variable

    Quote Originally Posted by jmcilhinney View Post
    Which is exactly what the first code example, entitled something like "Getting a single value", in my CodeBank thread does.
    Awww I shouldve assumed as much...

Posting Permissions

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



Click Here to Expand Forum to Full Width