English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I currently have ODBC Administrator on my workstation and it has been configured to get to the database. This part works. But, I need to know the actual code needed in VB to access this. From what I have seen it looks to be something like a record set definition. My books are old and this code is not in them. I need the code setup for this. Thanks

2006-06-26 23:31:54 · 4 answers · asked by Jim P 1 in Computers & Internet Programming & Design

4 answers

Please note for any of this to work you have to have the project references include the Microsoft ActiveX Data Objects library

dim conn as new ADODB.Connection
dim rs as new ADODB.Recordset

'Tell your connection what and how to connect
conn.ConnectionString= "DSN=DSNname;UID=SqlServerUserID;pwd=SqlServerPassword"

'open the connection
conn.open

'Run your SQL Query
set rs = conn.Execute("Select * from datatable")

'See if any records were returned we do this
'by seeing if the recordset is simoultaneously reporting
'that it is at the beginning and end of the record set
if not rs.EOF and not rs.BOF then


'Get the field by field name
myValue=rs("fieldName")

'Get the field by position in the return set
'This is a zero baed index
mySecondValue= rs(3)

'Now I move to the next record.
rs.MoveNext

if not rs.EOF then
'Get another value
myValue=rs("FieldName")
end if

end if

'now close and clean up

conn.Close
set rs = nothing
set conn=nothing

2006-06-27 00:07:31 · answer #1 · answered by cliffinutah 4 · 0 0

first on the staggering of the kind include gadget.records.SqlClient in the Imports ascertain you apart from mght have gadget.records too. dim strConn as string strConn = "records source = ; initial Catalog = , integrated protection = genuine" Dim SqlConnection cnSQL = new SqlConnection(strConn) you've now relating to a sq. Server Database.

2016-11-15 07:49:14 · answer #2 · answered by ? 4 · 0 0

Standard Security:
"Driver={SQL Server};Server=Aron1;Database=pubs;Uid=sa;Pwd=asdasd;"

Trusted connection:
"Driver={SQL Server};Server=Aron1;Database=pubs;Trusted_Connection=yes;" ;DataBase=pubs;"

2006-06-27 06:48:44 · answer #3 · answered by M.Raja 2 · 0 0

Read it here and learn my friend

http://www.google.co.uk/search?hl=en&q=Sql+database+via+Visual+Basic+6.0&btnG=Search&meta=

2006-06-27 00:10:40 · answer #4 · answered by Joe_Young 6 · 0 0

fedest.com, questions and answers