Question

ADO & DBF

Asked by: Maquiavelo

Here's my code:

Dim cn As ADODB.Connection

cn.ConnectionString = "Driver={Microsoft Visual Foxpro Driver};UID=;PWD=;SourceDB=c:\FileName.dbf;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;"
cn.Open

Set rs = New ADODB.Recordset
rs.Open "c:\Filename.dbf", cn, adOpenDynamic, adLockPessimistic, adCmdTable

then I want to add new records to the table:

rs.AddNew
..
..
rs.Update

Here tells me that I can't add any records because it's not a table, or something like that. (If need the exact error desc let me know).

Thanks in advance Mq.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2000-06-14 at 04:02:56ID10450540
Tags

adlockpessimistic

,

dbf

Topic

VB Database Programming

Participating Experts
5
Points
115
Comments
14

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. FoxPro DBF and ADO
    I am using ADO to manipulate FoxPro Database. I notice that the recordset that is open by DBF connection is not updatable, whereas recordset from DBC is updatable. The error message is "The Query is not updatable because the from clause is not from single simple table&qu...
  2. Convertin Foxpro dbf to ado rs
    How do you readin a foxpro dbf, converft it to and adodb.rs for insertion into an informix db?
  3. Displaying queries of dbf in IIS?
    I'm Running IIS On My XP Pro. I Have Managed To Convert The dbf (IV) to mdb and used asp to query it to output, but I Don't Want to Have To Keep Converting It Everyday. The Answer I'm Looking For Is Either: A Way For asp in iis to Display dbf queries, Or To Install Perl Into ...
  4. read and write data to .dbf file
    I want to read and write data to .dbf (visual foxpro file) file using visual basic i can read the data using simple ADODB.Connection and recordset object but i am not able to write data in the file. Please help me to do this

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: afpcosPosted on 2000-06-14 at 04:43:14ID: 2946265

rs.Open "c:\Filename.dbf", cn, adOpenDynamic, adLockPessimistic, adCmdTable

"c:\Filename.dbf" is not a name of a table, it is the path to the database

The statement should read

rs.Open "SELECT * FROM table",cn,adOpenDynamic, adLockPessimistic, adCmdTable

 

by: jrspanoPosted on 2000-06-14 at 04:46:06ID: 2946283

i think your open statement needs to be modified to tell the rs what data to return.  where you have c:\filename.dbf you need to put a sql command or table name.  the next statement where you have cn tells the rs what database you need to get the rs from.  YOu don't need to tell it again.

 

by: PHalsePosted on 2000-06-14 at 04:53:33ID: 2946333

To add to afpcos's comment

table could point to or an sql statement or a table directly.

rs.Open "TableName",cn,adOpenDynamic, adLockPessimistic, adCmdTable

Correct me if I am wrong in saying that the adCmdTable should be changed to adCmdText if using SQL instead of a table name.



 

 

by: jrspanoPosted on 2000-06-14 at 05:11:25ID: 2946458

Yes you must change to adCmdText if using a sql statement

 

by: TimCotteePosted on 2000-06-14 at 05:21:24ID: 2946526

All this is true, however the simple answer to using it in the way described, is to change the Source=c:\filename.dbf to source=c:\
and rs.Open "Filename",cn,....

This will work using the adCmdTable type.

 

by: TimCotteePosted on 2000-06-14 at 05:21:54ID: 2946529

Sorry, that should be SourceDB= in the connection string not Source=.

 

by: evertdPosted on 2000-06-16 at 01:21:11ID: 2961054

"c:\Filename.dbf" is not a name of a table, it is the path to the database

The statement should read

rs.Open "SELECT * FROM table",cn,adOpenDynamic, adLockPessimistic, adCmdTable

 

by: TimCotteePosted on 2000-06-16 at 05:51:59ID: 2963418

evertd, c:\filename.dbf is the name of the table, foxpro tables are contained within one file, one table per file. This is why in my comment which should work, and I would appreciate if maquiavelo would confirm or deny this, that if the sourcedb is changed to the path "c:\" then filename.dbf can be used in the open statement as I described earlier.

Also it would appear that you have simply copied a segment of afpcos's comment and posted it as an answer. This is contrary to the principals of this site and I would suggest that you withdraw this answer.

Maquiavelo, please could you follow up on this thread and either decide whether you have received a satisfactory solution or ask for more info. In either case I would suggest that you reject evertd's "answer".

If no action is taken on this thread then I will refer the matter to customer services.

 

by: MaquiaveloPosted on 2000-06-17 at 04:36:36ID: 2972472

 Ok. These R the things I've tried on the Open method and did not work.

Using the path and cmdTable:

?err.Description
The query is not updatable since the FROM clause is not the name of a simple table.
?err.Number
-2147418113

Using my table name with cmdTable or SELECT statement with cmdText:
      
?err.Description
The ODBC driver does not support the required properties
?err.Number
-2147217887

  Note the err.desc are translations.

  I've been developing VB apps for 4 years buut never using ADO, so pls skip the dummy explanation.

  Well, any ideas...

 

by: TimCotteePosted on 2000-06-19 at 00:53:41ID: 2986470

maquiavelo:

This is how I have used your example,

Private Sub Command1_Click()
Dim cn As New ADODB.Connection

cn.ConnectionString = "Driver={Microsoft Visual Foxpro Driver};UID=;PWD=;SourceDB=c:\testbed;SourceType=DBF;Exclusive=No;BackgroundFetch=Yes;Collate=Machine;Null=Yes;Deleted=Yes;"
cn.Open

Set rs = New ADODB.Recordset
rs.Open "test.dbf", cn, adOpenDynamic, adLockPessimistic, adCmdTable

rs.AddNew
rs.fields(0).Value = InputBox(rs.fields(0).Name, "Enter", rs.fields(0).Value)
rs.Update
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing

End Sub

The folder c:\testbed is given in the sourcedb, and the file test.dbf is in this folder. If the program is run, it prompts for entry and the record is added to the table.

A few things to note, if you include the pathname to the table in the rs.open line then it will open the table as a select statement but it will not allow the updates, you will get the simple table error you describe. If however the path is in the sourcedb parameter and not in the rs.open then it seems to work ok. I cannot explain this other than a Microsoft dodgy implementation of the functions.

Hope this helps you some.

 

by: MaquiaveloPosted on 2000-06-20 at 07:12:10ID: 3009741

Comment accepted as answer

 

by: MaquiaveloPosted on 2000-06-20 at 07:12:10ID: 3009742

 Thanks! Finally worked! This is my first time with ADO and my last time!!

 

by: TimCotteePosted on 2000-06-20 at 07:22:33ID: 3009854

Don't write ADO off, in my opinion it is much easier to use than DAO when you get the hang of it. Microsoft will probably also phase out DAO over time and you will be left with ADO until they invent something new to supersede that as well.

 

by: MaquiaveloPosted on 2000-06-20 at 13:08:30ID: 3015113

 Yeah, U R right, but since I'm not professionally in VB anymore I'm gonna keep using DAO for my own projects.

 

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...