Results 1 to 3 of 3

Thread: DBGrid ??

  1. #1

    Thread Starter
    New Member
    Join Date
    May 1999
    Location
    Toronto,Ontario,Canada
    Posts
    14

    Post

    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



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

  2. #2
    New Member
    Join Date
    Aug 1999
    Location
    Foxboro
    Posts
    4

    Post

    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

  3. #3
    New Member
    Join Date
    Aug 1999
    Posts
    5

    Post

    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
    [email protected]
    ------------------


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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width