Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieving data from MS Access mdb files
Message
From
12/11/2005 08:08:42
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
11/11/2005 16:13:09
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01067922
Message ID:
01068069
Views:
20
This message has been marked as a message which has helped to the initial question of the thread.
>I've read several FAQs and postings, but I can't get it right.
>
>Here's a representative attempt:
>
>------------------ Start Code ----------------------------------
>constring = "DBQ=c:\a_testing\ODBC\mytable.mdb;" ;
> + "Driver={Driver do Microsoft Access (*.mdb)};" ;
> + "DriverId=25;FIL=MS Access;" ;
> + "MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;"
>
>sqlHandler = SQLSTRINGCONNECT(constring)
>IF sqlhandler < 1
> MESSAGEBOX("No made connection")
> RETURN
>ENDIF
>
>sqlselect = "SELECT * FROM c:\a_testing\ODBC\mytable.mdb"
>
>IF SQLEXEC(sqlHandler,sqlselect,"myCURSOR") <0
> MESSAGEBOX("Error - Can't Execute....")
>ENDIF
>----------------- End of Code --------------------------------------
>
>The SQLSTRINGCONNECT(constring) command seems to work fine (no error message).
>I have also set it up using the wizard.
>
>The problem is with the SQLEXEC(sqlHandler,sqlselect) command.
>The error message appears.
>
>Any suggestions?
>
>Also, can anyone point me to the specs that explain the options in the "constring" definition above?
>
>
>Thanks,

Connection string is right. For other type of connection strings check www.connectionstrings.com.
Check FAQ #8039
You selct from a table in MDB not directly MDB itself. This sample might help:
Public oForm
oForm = Createobject('myForm')
oForm.Show()

Define Class myForm As Form
  Height = 450
  Width = 850
  DataSession=2
  Caption='Show Access Data'

  Add Object lblAccess As Label With ;
    Caption = "Access Database", ;
    Left = 10, Top = 15, Width = 100

  Add Object txtMDBlocation As TextBox With ;
    Left = 112, Top = 12, Width = 520

  Add Object cmdBrowse As CommandButton With ;
    Top = 10, Left = 640, Caption = "Browse", Autosize=.t.

  Add Object lblTables As Label With ;
    Caption = "Tables", Left = 20, Top = 40, Width = 40

  Add Object lstTables As ListBox With ;
    Height = 400, Left = 65, Top = 40, Width = 265

  Add Object grdShow As Grid With ;
    Height = 400, Left = 340, Top = 40, Width = 500

  Procedure listtables
    Local lnConnHandle,lcMDB
    With This.txtMDBlocation
      If Empty(.Value) Or !File(.Value)
        Return
      Endif
      lcMDB = Trim(.Value)
    Endwith

    lnConnHandle = ;
     Sqlstringconnect("Driver={Microsoft Access Driver (*.mdb)};Uid=Admin;DBQ="+m.lcMDB)
    SQLTABLES(m.lnConnHandle, ['TABLE'], 'crsTables')
    SQLDISCONNECT(m.lnConnHandle)
    Select crsTables
    This.lstTables.Clear()
    Scan
      This.lstTables.AddItem(crsTables.table_name)
    Endscan
  Endproc


  Procedure txtMDBlocation.LostFocus
    Thisform.listtables()
  Endproc


  Procedure cmdBrowse.Click
    This.Parent.txtMDBlocation.Value = Getfile('MDB','','',0,'Select Access Database')
    Thisform.listtables()
  Endproc


  Procedure lstTables.InteractiveChange
    Local lnConnHandle,lcMDB,lcSQL
    With This.Parent.txtMDBlocation
      If Empty(.Value) Or !File(.Value)
        Return
      Endif
      lcMDB = Trim(.Value)
    Endwith

    lcSQL = 'select * from "'+Trim(This.Value)+'"'
    lnConnHandle = ;
     Sqlstringconnect("Driver={Microsoft Access Driver (*.mdb)};Uid=Admin;DBQ="+m.lcMDB)
    SQLEXEC(m.lnConnHandle,m.lcSQL,'crsLocal')
    SQLDISCONNECT(m.lnConnHandle)
    With This.Parent.grdShow
      .ColumnCount = -1
      .RecordSource = 'crsLocal'
    Endwith
  Endproc
Enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform