|
-
Oct 29th, 1999, 06:35 AM
#1
Thread Starter
Hyperactive Member
I got this code from www.planetsourcecode.com and I was wondering exactly where to put it and how to use it, because they weren't very clear.
Public Sub CONNECTODBC()
Dim dbname As String
Dim dataset As String
Dim User3 As String
Dim pass As String
Dim db As Database
Dim X As String
User3 = "USERID"
pass = "PSWD"
dataset = "YOUR DSN NAME"
dbname = "DATABASE NAME"
X = "ODBC;database=" & dbname & ";DSN=" & dataset & ";UID=" & User3 & ";PWD=" & pass
Set db = OpenDatabase("", False, False, X)
db.Close
End Sub
If you could help me figure out exactly how to use it, or figure out a better way to connect to a SQL server, I would appreciate it.
------------------
Thanks,
Ryan
[email protected]
ICQ# 47799046
-
Oct 29th, 1999, 10:23 AM
#2
Frenzied Member
The code you posted opens a database defined to ODBC (DSN = dataset name, you see these in the odbc control panels). Not very useful, the database is only open as long as the routine is.
-
Oct 29th, 1999, 01:52 PM
#3
Thread Starter
Hyperactive Member
ok, so how do I go about accessing a database w/o using the Data Control in VB?
------------------
Thanks,
Ryan
[email protected]
ICQ# 47799046
-
Oct 30th, 1999, 11:52 AM
#4
Frenzied Member
What is it you would like to do?
-
Nov 1st, 1999, 03:47 AM
#5
Thread Starter
Hyperactive Member
I would like to be able to access a Sybase SQL database WITHOUT using the ugly looking data control. I want to have different controls for the actual moving around inside the database, so I don't want to use the built-in data control. How do I open a database and access it's contents w/o using the data control?
------------------
Thanks,
Ryan
[email protected]
ICQ# 47799046
-
Nov 1st, 1999, 05:30 AM
#6
Frenzied Member
Fair enough. If you modify your odbc open code so that the database object (db) is global (and move the db.close to the form exit) your database, once you've created the DSN(s), will remain open for the life of the program.
After you've got the database open, you then use recordsets to do the actual work. Here's some code that gets data based upon a select statement.
Code:
Qry = "select * from table where field = '" & form.field1.Text & "' order by sortkey"
Set Rs = db.OpenRecordset(Qry, dbOpenSnapshot)
If Rs.EOF = False Then
Do While Not Rs.EOF
form.field2.Text = Rs.Fields(0)
form.field3 = Rs.Fields(1)
' [...]
form.field999.value = CInt(Rs.Fields(999))
Rs.MoveNext
Loop
End If
Rs.Close
Depending on the ODBC implementation, you can use pretty much every defined method for recordsets (rs.movefirst, rs.movelast, rs.movenext, rs.moveprevious). You need to make sure you're checking the correct properties, for the type of search you perform.
[This message has been edited by JHausmann (edited 11-01-1999).]
-
Nov 1st, 1999, 07:17 AM
#7
Thread Starter
Hyperactive Member
Ok, GREAT! I'll give that a try and let you know.
------------------
Thanks,
Ryan
[email protected]
ICQ# 47799046
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|