|
-
Sep 9th, 2000, 08:15 AM
#1
Thread Starter
Fanatic Member
Ok. I've just started databases since this is the first time I need to use one 
Can anybody tell me why this won't work:
Code:
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
Dim sql As String
conn.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.3.51;Data Source=D:\Visual Studio\vb98\Players.mdb")
conn.Open
sql = "Select * From First_Name"
'Raises an error: The Microsoft Jet Database engine cannot find the input
'table or query 'First_Name'. Make sure it exists and that its name is
'spelled correctly
Call rs.Open(sql, conn)
The path is correct. I'm pretty sure about the 'First_Name' bit. That's what it says on top of the column in Access' Datasheet view. I also tried it using 'FirstName' because that's what the box says in it in Access' Design View.
Also, I can't use any compenents, because when it works, I'm going to turn it into ASP (and I'll use CreateObject and all that)
I looked through my VB Book and the Tutorials on this site, but they all use some sort of control.
Any help would be appreciated,
Me.
-
Sep 9th, 2000, 09:48 AM
#2
Hyperactive Member
First, take out the Call reserve word in Call rs.Open
You don't need it.
Second, it appears that in your database, you have a table with a column called First_Name. In your SQL statement, you want to use the name of the table and not the column, so it would be "Select * From " and then the table name, like this:
Code:
Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
Dim sql As String
conn.ConnectionString = ("Provider=Microsoft.Jet.OLEDB.3.51;Data Source=D:\Visual Studio\vb98\Players.mdb")
conn.Open
sql = "Select * From 'and then the table name
rs.Open(sql, conn)
-
Sep 9th, 2000, 12:42 PM
#3
Thread Starter
Fanatic Member
I'm afraid I'd already tried all of the possible name cominations in the SQL script:
Code:
'I've tried:
sql = "Select * From [First Name]"
'And:
sql = "Select * From First_Name"
'AND
sql = "Select * From FirstName"
But they all raise the error I explained.
Maybe there's something else?
Please help, I'll give you a really big thanks,
Moi.
-
Sep 9th, 2000, 04:15 PM
#4
Lively Member
Make sure that your program is really connected to the database. You can check it in the debug mode or insert a statement in your code follow this:
Code:
If conn.state = adstateclose then
msgbox "Can't connect to the database."
endif
-
Sep 10th, 2000, 05:20 AM
#5
Thread Starter
Fanatic Member
I tried it with adStateClosed and it always goes through the 'else' bit I added, meaining that it is connected, right?
Maybe there are different 'providers' I could use instead of that Jet thing? (I'm using Access 97)
Any help very welcome indeed.
-
Sep 10th, 2000, 09:57 AM
#6
Fanatic Member
V(ery) Basic
Is First_Name a field in the table because you need to specify the table name itself in the SQL
Code:
sSQL = SELECT * FROM tblCustomers
rs.Open sSQL conn
Gary Lowe 
VB6 (Enterprise) SP5
ADO 2.6
SQL Server 7 SP3
OK I know my spelling and grammer is crap so don't quote me on it!
To err is human to take the P! is only natural !!
Click on the top section of image for Marcus Miller website and bottom section of image for 'Run For Cover' sound clip

-
Sep 10th, 2000, 11:12 AM
#7
This code works perfect for me
I am using access 2k.
but it should work with '97 too.
Code:
Private Sub Form_Load()
Dim oCon As ADODB.Connection
Dim oRS As ADODB.Recordset
Dim sSQL As String
Set oCon = New ADODB.Connection
Set oRS = New ADODB.Recordset
With oCon
.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=c:\my documents\MyPages.mdb;"
.Open
End With
'tblMyPages is the table, PageID is the field.
sSQL = "SELECT * FROM tblMyPages WHERE PageID='LTEd'"
Set oRS = oCon.Execute(sSQL)
'content is a field of my DB
txtText = oRS("Content")
oCon.Close
End Sub
[Edited by denniswrenn on 09-10-2000 at 12:15 PM]
-
Sep 11th, 2000, 01:59 PM
#8
Thread Starter
Fanatic Member
Ok.
Thanks y'all. it now works, you see the problem was that I thought that you should pass the name of the field, not the entire table. 
Oops. I told you I was a Database beginner, didn't I?
It now works like a house on fire.
That's not right is it?
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
|