PDA

Click to See Complete Forum and Search --> : DBGrid ??


Harry
Aug 9th, 1999, 07:21 PM
Wondering if anyone out there ever suceed exporting a DBase database to a DBGrid. These are the stuff I did in my program. Set the connect property on the data control to DBase, set the databasename property to the path of the folder containing the dbf table, set the recordsource property to the name of the table with the dbf extension, and bound the grid to the data control. However, when I tried to export the table to the grid using the code below I got the following errors: "Run-time error 3343. Unrecognized database
format. C:\dry.dbf"

I not sure what might have caused this error. I do know it is a DBase format. Can you look at my code and see if it is correct. If there is a better way to do this please let me know. Thanks a lot!!

P.S. Please, provide some sample code.

Dim dbsTemp As Database
Dim rstTemp As Recordset
Dim QueryString As String

Set dbsTemp = OpenDatabase("C:\dry.dbf")
Set rstTemp = dbsTemp.OpenRecordset("dry", dbOpenDynaset)

QueryString = "SELECT * FROM Kraftdry"
With rstTemp
Form2.Data1.Refresh
Form2.Data1.RecordSource = QueryString
Form2.DBGrid1.ClearFields
Form2.DBGrid1.ReBind
End With



------------------

david1
Aug 9th, 1999, 09:06 PM
I would use ADODB instead.
This is a piece that connect to a SQL server, but for a database is similar. If you are using vb6 you can add a form and use the wizard to add a data form. The wizard will help you set up the connection to the database.

Dim db As ADODB.Connection
'Sets up the connection to the server
Dim serverName, UserId, dbUser, SqlProvider, ShapeProvider As String
serverName = "Server name"
'DLC Note that temporarly the user id will be set here
'normally will come from the login script
UserId = "sa"
dbUser = "CBD" 'Control block Parameter Atributes database
Set db = New Connection
SqlProvider = "SQLOLEDB"
db.Provider = SqlProvider
db.CursorLocation = adUseClient
db.ConnectionTimeout = 60
db.ConnectionString = "Server=" & serverName & _
";uid=" & UserId & _
";pwd=" & _
";database=" & dbUser

db.Open

David

MGC
Aug 9th, 1999, 10:15 PM
This should work in VB4 and VB5.

You may need to change the "dBase 5.0;" depending on the dBase version of your .dbf file.

Dim dbsTemp As Database
Dim rstTemp As Recordset
Dim QueryString As String

Set dbsTemp = OpenDatabase("C:\", False, False, "dBASE 5.0;")
QueryString = "SELECT * FROM Dry"
Set rstTemp = dbsTemp.OpenRecordset(QueryString, dbOpenDynaset)
Set Form2.Data1.Recordset = rstTemp
Form2.DBGrid1.ClearFields
Form2.DBGrid1.ReBind


MGC
xmgx@aol.com
------------------


[This message has been edited by MGC (edited 08-10-1999).]