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
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.
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)
Re: Read field from database into variable
Quote:
Originally Posted by
albel
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.
Re: Read field from database into variable
Quote:
Originally Posted by
albel
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.
Re: Read field from database into variable
Quote:
Originally Posted by
Tom.Net
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.
Re: Read field from database into variable
Quote:
Originally Posted by
jmcilhinney
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... :bigyello: