Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Connecting to an MS Access Database
Message
 
To
25/06/2003 15:59:16
Gerry Schmitz
GHS Automation Inc.
Calgary, Alberta, Canada
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00802042
Message ID:
00804089
Views:
31
Ok, now I see. I think I want to concentrate on the ADO way of doing things. I took the code you showed me and modified it to READ my database and that worked OK with the exception of the SELECT statement was unable to read the two word table name of "Sample Upload". I had to rename my table to get it to work. I will not be allowed to do this in my real application. How do I get the SELECT statement :
 rst.Open ( ;
>      "SELECT * FROM Customers WHERE Region = 'WA'", ;
>      cnn, adOpenForwardOnly, adLockReadOnly )
to read the two word table name "Sameple Update"?

So I got it to read an Access Table and understand that. However, the main function I will be doing with this small App is starting with an empty Table within an Access database and writing data from my VFP Basd application (from multiple views) into this empty table in Access. Once I establish the connection and open the recordset, how do I WRITE to the table the values from my VFP Views?

I've tried reviewing the OLB file for ACCESS in VFPs Object Browser, but I had know idea where to start looking for that info with the Properties, Events, and Methods?

Where can I find information to leare about the things you showed me in the code below? Things like "cnn = CREATEOBJECT( "ADODB.Connection" )", and things like "rst.MoveFirst"? Do I find those things in Access Help, VFP Help, etc. Any suggested reading on that?

Thank you so much for your help. I"m really under pressure to get started on this. I know I could simply Query my data out to a DBF file and them "Import" it from within Access, but I would rather do it all from within my Application.

Thanks
Elgin


>Well, one has to start somewhere. I'm including 2 simple examples that "read" from the NorthWind database; one in ADO and one in DAO.
>
>I prefer DAO, because one can operate on tables directly like in VFP vs using the equivalent of "views" in ADO. However, one can argue that DAO is obsolete; your choice.
>
>You can play with the examples and attempt to read your Access tables first; then progress to updating. Let me know if you get stuck.
>
>
>   CLEAR
>*-----------------------------------------------------------------------
>*  ADO Example.
>*-----------------------------------------------------------------------
>   #DEFINE adOpenForwardOnly  0
>   #DEFINE adLockReadOnly     1
>
>   #DEFINE DATA_SOURCE  ;
>      "C:\Program Files\Microsoft Office\Office\Samples\Northwind.MDB"
>
>   cnn = CREATEOBJECT( "ADODB.Connection" )
>   rst = CREATEOBJECT( "ADODB.Recordset" )
>
>   *  Open the connection
>
>   cnn.Open( ;
>      "Provider=Microsoft.Jet.OLEDB.4.0;" + ;
>      "Data Source=" + DATA_SOURCE + ";" )
>
>   *  Open the forward-only, read-only recordset
>
>   rst.Open ( ;
>      "SELECT * FROM Customers WHERE Region = 'WA'", ;
>      cnn, adOpenForwardOnly, adLockReadOnly )
>
>   *  Print the values for the fields in the first record
>
>   rst.MoveFirst
>
>   LOCAL LO_Field
>
>   FOR m.i = 0 TO rst.Fields.Count - 1
>      m.LO_Field = rst.Fields.Item[ m.i ]
>
>      WITH m.LO_Field
>         ? .Name, "=", .Value
>      ENDWITH
>   NEXT
>
>   *  Close the recordset and connection.
>
>   rst.Close()
>   cnn.Close()
>
>*-----------------------------------------------------------------------
>*  DAO Example.
>*-----------------------------------------------------------------------
>
>   o_Jet = CREATEOBJECT( "DAO.DBEngine.36" )
>
>   o_DB = o_Jet.OpenDatabase( ;
>      "C:\Program Files\Microsoft Office\Office\Samples\Northwind.MDB" )
>
>   o_Rs = o_DB.OpenRecordset( "Customers" )
>   o_Rs.MoveFirst()
>
>   FOR m.i = 0 TO o_Rs.Fields.Count - 1
>      ? o_Rs.Fields[ m.i ].Name, "=", o_Rs.Fields[ m.i ].Value
>   NEXT
>
>   o_Rs.Close()
>   o_DB.Close()
>
>
>
>>Thank you for the info. I am really baffled and frustrated at this point. I'm still not sure which way to go. I actually have two different projects just starting up involving ACCESS Databases.
>>
>>I tried reading about COM, ADO, OLEDB,etc for Access, but I don't know where to start. The main project I want to do right now is retrieve some data from several FP2.6 tables into one table in an Access database. I've tried using ODBC to write to the table but get connectivity errors due to field names such as "5-Hydroxy-methyl-furaldehyde", stating there are invalid characters.
>>
>>I would really like to learn how to use COM to write this data to the Access table from within my VFP 6.0 Application. (soon to be VFP 7 app when I get the time.)
>>
>>I already have procedeures and routines in my app that retrieve the data I need into parameterized views within VFP. So I guess I would be writing the data from these parameterized views instead of FP2.6 tables.
>>
>>If I could just get a "kick start" in the right direction. I've seen in other threads how to create an adodb.recordset and adodb.connections (message id#785256). But how do I manipulate data, actually write data from my views into this "recordset", table.
>>
>>Help is surely appreciated.
>>
>>Thank You
>>
>>>>My question is, what will be my best way to connect to the MS Access Database? This is my first attempts at Remote Views and Connections. Is ODBC by only and best choice? Is COMM or DCOM a choice for me?
>>>
>>>You can use Automation (i.e. COM) to connect to MS Access Databases (.MDBs) via DAO or ADO (the 2 commonly used object models).
>>>
>>>Which is "best" (COM, remote views and ODBC) is maybe more a matter of personal preference.
>>>
>>>I prefer COM because it is object oriented, and since VB generally uses DAO or ADO, it's easier to port Access samples (which are many) from VB to VFP ... I also think COM (in this case) is more fun.
Elgin Rogers
Epic Solutions
www.epicsolutions.net
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform