473,395 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Updating FoxPro DBF From C#

I am trying to Delete records from Fox Pro Free Tables (.DBF) using
C#. I am able to insert and view data with no problems but when I try
to delete - no luck. It appears that I need to run a "Pack" command
but I receive the error "File must be opened exclusively." on the Pack
Command. The code is below and the first command "Delete From
Progress" marks all rows for deletion but does not remove them. I've
tried Exclusive=On but still get the same error.
public FoxProConnector(string tableName){
this.DBFTableName = tableName;
OleDbConnection oConn = new OleDbConnection(@"Provider=VFPOLEDB.1;Data
Source=c:\\" + tableName +";Mode=ReadWrite;");
oConn.Open();
//OleDbCommand oCom = new OleDbCommand("Insert into
Progress(nProgress) values(990)");
OleDbCommand oCom = new OleDbCommand("Delete From Progress");
oCom.Connection = oConn;
oCom.ExecuteNonQuery();
oCom = new OleDbCommand("PACK");
oCom.Connection = oConn;
oCom.ExecuteNonQuery();
}

Unhandled Exception: System.Data.OleDb.OleDbException: File must be
opened exclusively.
**Removed Several Lines**
at OrderHeader.Form1.Main() in c:\documents and settings\scottm\my
documents\visual studio projects\orderheader\form1.cs:line 126
Nov 15 '05 #1
3 24265
aaa,

Technically, when you issue a delete, the rows are flagged with a delete
flag. You aren't going to see those rows on subsequent selects unless the
runtime for foxpro has "SET DELETE ON". If you want to pack the tables, you
shouldn't do this after every database operation, as it can be costly. I
would recommend issuing a pack as part of a regular maintinence and not on
every database operation.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<aaa> wrote in message news:ej*************@TK2MSFTNGP10.phx.gbl...
I am trying to Delete records from Fox Pro Free Tables (.DBF) using
C#. I am able to insert and view data with no problems but when I try
to delete - no luck. It appears that I need to run a "Pack" command
but I receive the error "File must be opened exclusively." on the Pack
Command. The code is below and the first command "Delete From
Progress" marks all rows for deletion but does not remove them. I've
tried Exclusive=On but still get the same error.
public FoxProConnector(string tableName){
this.DBFTableName = tableName;
OleDbConnection oConn = new OleDbConnection(@"Provider=VFPOLEDB.1;Data
Source=c:\\" + tableName +";Mode=ReadWrite;");
oConn.Open();
//OleDbCommand oCom = new OleDbCommand("Insert into
Progress(nProgress) values(990)");
OleDbCommand oCom = new OleDbCommand("Delete From Progress");
oCom.Connection = oConn;
oCom.ExecuteNonQuery();
oCom = new OleDbCommand("PACK");
oCom.Connection = oConn;
oCom.ExecuteNonQuery();
}

Unhandled Exception: System.Data.OleDb.OleDbException: File must be
opened exclusively.
**Removed Several Lines**
at OrderHeader.Form1.Main() in c:\documents and settings\scottm\my
documents\visual studio projects\orderheader\form1.cs:line 126

Nov 15 '05 #2
In news:%2******************@TK2MSFTNGP10.phx.gbl,
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> posted:
Technically, when you issue a delete, the rows are flagged with a
delete flag. You aren't going to see those rows on subsequent
selects unless the runtime for foxpro has "SET DELETE ON".


Hi Nicholas,

The FoxPro command SET DELETED ON hides deleted records. It corresponds to
the Deleted checkbox in the ODBC driver setup - in other words, when the box
is checked, DELETED is ON and deleted records are hidden. A little
counterintuitive.

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
ci**************@mvps.org, www.cindywinegarden.com
Nov 15 '05 #3
In news:ej*************@TK2MSFTNGP10.phx.gbl,
aaa <aaa> posted:
I am trying to Delete records from Fox Pro Free Tables (.DBF) using
C#. I am able to insert and view data with no problems but when I try
to delete - no luck. It appears that I need to run a "Pack" command
but I receive the error "File must be opened exclusively." on the Pack
Command.
When a FoxPro record is marked for deletion you can consider it to be
deleted, as long as you're running with Deleted set ON. The reasons to
permanently remove records are few - if your tables are becoming impossibly
large, or if you need to re-use a primary key. IMHO a key value that's
reused isn't really a PK. Is there some specific reason you need to PACK the
table? Be aware that having exclusive use of the table can only be done when
the users are out of the system.
The code is below and the first command "Delete From
Progress" marks all rows for deletion but does not remove them. I've
tried Exclusive=On but still get the same error.
Um - which error - do you get an error from the Delete command, an error
when you try to PACK, or an error when you try some operation that requires
the records to be permanently removed?
....
oCom = new OleDbCommand("PACK"); Unhandled Exception: System.Data.OleDb.OleDbException: File must be
opened exclusively.


The following article describes how to PACK a table via ODBC. It should help
you get started doing it through OLE DB:

HOWTO: Pack a Table Through the Visual FoxPro ODBC Driver (VFPODBC.dll)
http://support.microsoft.com/default...b;en-us;234756

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
ci**************@mvps.org, www.cindywinegarden.com
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gene Vital | last post by:
Hi all. I am using Visual FoxPro via ODBC to update records on a 7.3.4 PostgreSql server and it appears that it always uses delete/insert instead of updating the current record. Can this be...
13
by: Simon Bailey | last post by:
I am a newcomer to databases and am not sure which DBMS to use. I have a very simplified knowledge of databases overall. I would very much appreciate a (simplifed) message explaining the advantages...
2
by: Salad | last post by:
OS = WinXP & Win98. Access = A97 & AXP Q1) Where can I find the VFP ODBC driver at Microsoft. I have been working developing an app in Access that will link to some DOS FoxPro tables. I...
4
by: RL Stevenson | last post by:
Often I want to change the Enable or Visibility on a control when some other control on the form changes. Or maybe I need to make a change to the DataSource on a combo box when the user makes a...
1
by: GPBSOFT | last post by:
I am Italian developer, escuse me for my bad English I have a problem with ODBC. I must link to a database from Visual FoxPro, I have installed Windows XP Professional with service pack 2. When I...
3
by: Sarah | last post by:
Hi I am using vb.net Is it possible to fetch data from foxpro tables (vfp8) and update tables in sql server 2000? The table structures of the foxpro tables are different from those in sql...
3
by: Amar | last post by:
I have a abc.PRG file in visual foxpro 8.0. I can run this file using visual foxpro environment and it creates a table X.dbf in the same folder where this program file is and populates some data...
2
by: Toco | last post by:
Hello. I have app written in C# that we are testing. The executable is shared on our network. The method we are testing is a call to a foxpro table. The call is made to query the table, then...
7
by: z71mdridin | last post by:
I have an asp.net website that uses Form authentication to authenticate users. I need to provide users with a report based on FoxPro data that resides on a remote server. When I attempt to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.