Keeping SQL results in various variables

R

Rui Alvares

Hi every body,



I'm not a good programmer in SQL and Visual Basic and so, I need your help.

Below is some code that gives data from a row of a table.

This data is stored in variables value_1, value_2 and value_3.

What I want is how to make code to read some rows of data stored in a table
and keep that data in various variables?



Dim conn, rst 'deklarieren der Variable 'variable declaration



Set conn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")



conn.Open "Provider=MSDASQL;DSN=WinCCFlexible"



Dim SQL_Tabelle



On Error Resume Next



SQL_Tabelle = "SELECT * FROM " & tabname_1 & " WHERE Nr = " & Dat_Nr



Set rst = conn.Execute(SQL_Tabelle)



If Not (rst.EOF And rst.BOF) Then
rst.MoveFirst


value_1 = rst.Fields(1).Value
value_2 = rst.Fields(2).Value
value_3 = rst.Fields(3).Value
name_1 = rst.Fields(1).Name
name_2 = rst.Fields(2).Name
name_3 = rst.Fields(3).Name

rst.Close


End If



Set rst = Nothing
Set conn = Nothing
Err.Clear





Thanks in advance



Rui Álvares
 
M

Mike Glen

Hi Rui,

Try posting on the developer newsgroup. Please see FAQ Item: 24. Project
Newsgroups. FAQs, companion products and other useful Project information
can be seen at this web address: http://project.mvps.org/faqs.htm

Mike Glen
Project MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top