Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing Data from a DB in Variables 1

Status
Not open for further replies.

Loggerhead2000

Programmer
Mar 23, 2003
11
US
Hello, Here is my problem (well not really) I am write an application that I want to store Data from a relational DB in to variable so I can use them else where in my program(Send the values into functions). I'm connecting to the DB through code not through a data control. I tried connecting it straight to a variable but it didn't work.
I Got it to work by binding it to a lable control and then taking it's caption prop. I was just wondering if there was a better way to do it?

Thanx Timmeh
 
What I like to do is to retrieve that data from the database via an ADO recordset object. Then either deal with the recordset object or, if there will be lots of data manipulation, I place the data from the recordset into a UDT array variable.

Then just reverse the process to update the data. Thanks and Good Luck!

zemp
 
I don't know what a UDT array variable is nor how to use one, guess I have a little research to do.

Thank you Zemp
 
A UDT is a User Defined Type data type. It can be made up of strings, integers, dates, doubles, etc.. You define what it contains.

Declare the UDt in a module similar to,

Public Type myUDT
Var1 as String
Var2 as integer
...
End Type

Create an array like,

Dim myArray() as myUDT 'dynamic declaration

To access and display 'Var1' in the first row of data use.

text1 = myArray(0).Var1

Now I use each variable within the UDT to represent a field value in the recordset and the array elements represent the row within the recordset or table. This way I don't have to deal with a double subscripted array and the specific data can be held in its correct data type.

But as you suggested it is a good idea to look thing up in the help files, on msdn or search this forum. The more information you have the better. Thanks and Good Luck!

zemp
 
You could also just use the ADO GetRows method, to return a 2 dimensional array as Array(Value, FieldName), which is generally alot fatser than looping through a recordset to get the data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top