|
-
Nov 7th, 2001, 06:46 AM
#1
Thread Starter
Addicted Member
Acces
Can i open a database connection to an Acces 2000 database using a connectionstring?
(like i open a SQLserver database?)
The following code doesn't work; can you make it work?
VB Code:
'references: Microsoft ActiveX Data Objects 2.6 Library
Dim Conn As ADODB.Connection
Dim RS As ADODB.Recordset
Dim CS As String
CS = "DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=C:\ProjectsVB\Experiment\testdb.mdb;DefaultDir=;UID=;PWD=;"
Conn.Open CS
-
Nov 7th, 2001, 06:50 AM
#2
Member
You declare the connection and the recordset but you never instantiate them. Try adding:
Set Conn = New Connection
Before opening connection.
Note: you will also have add this:
Set RS = New RecordSet
-
Nov 7th, 2001, 06:58 AM
#3
Thread Starter
Addicted Member
That's great help ! It works now, but now i have a problem with Conn.Open CS
Is my connectionstring build right?
-
Nov 7th, 2001, 07:06 AM
#4
Thread Starter
Addicted Member
I'm sorry, the problem is not that. My connection opens, but it is with something else i had problems:
VB Code:
Set Conn = New ADODB.Connection
Set RS = New ADODB.Recordset
CS = "DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=C:\ProjectsVB\Experiment\testdb.mdb;DefaultDir=;UID=;PWD=;"
Conn.Open CS
SQL = "Select * from tb_Customers"
Set RS = Conn.Execute(SQL)
RS.MoveFirst
RS.MoveLast
MsgBox RS.RecordCount
Set Conn = Nothing
Set RS = Nothing
The error occurs on RS.Movelast. This seems to be a problem with this recordset.
When i don't do movelast and movefirst, i get RecordCount = -1, although there are several records in my table.
-
Nov 7th, 2001, 07:19 AM
#5
Member
By default you are opening the recordset with server side cursor.
Try adding this:
Conn.CursorLocation = adUseClient
-
Nov 7th, 2001, 07:23 AM
#6
Thread Starter
Addicted Member
This doesn't work. I also tried changing the .CursorType to each of the 4 types, but none of them works. I always get a message "Rowset does not support fetching backwards"
-
Nov 7th, 2001, 07:31 AM
#7
Member
Not sure what to tell you. This works for me:
----------------------------------------------------------
Option Explicit
Private adoRs As New ADODB.Recordset
Private Conn As New ADODB.Connection
Private Sub Form_Load()
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Genetics\Genetics.mdb;Persist Security Info=False"
Conn.CursorLocation = adUseClient
Conn.Open
Set adoRs = Conn.Execute("Select * from change")
adoRs.MoveFirst
adoRs.MoveLast
MsgBox adoRs.RecordCount
End Sub
Server side cursors will always return -1 for a record count.
-
Nov 7th, 2001, 07:43 AM
#8
Thread Starter
Addicted Member
-
Nov 7th, 2001, 08:22 AM
#9
Thread Starter
Addicted Member
Showing data in Grid
I want to show the results of my query in a grid.
Can i say something like:
Grid.recordsource = RS ???
What grid do i have to take then? (i see 3 kinds of them: datagrid control, data bound grid control, ms flex grid control)
-
Nov 7th, 2001, 09:01 AM
#10
Member
Set datagrid1.datasource = rs
The datagrid control works fine.
-
Nov 7th, 2001, 09:06 AM
#11
Thread Starter
Addicted Member
What is the difference between datagrid and data bound grid? And flex grid, what is that used for?
I first tried this thing:
DGrid.DataSource = RS
But it didn't work.
In your example i saw that i had to do:
SET dgrid.datasource = RS
(this works)
When do i have to use Set and when not?
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
|