Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to zap or pack a DBF in ASP net
Message
General information
Forum:
Visual FoxPro
Category:
Visual FoxPro and .NET
Miscellaneous
Thread ID:
01132137
Message ID:
01132229
Views:
15
Timothy,

In VFP open a database containing a table you want to pack or zap. Type in the Command Window:
MODIFY PROCEDURE
In opening window type the following (suppose there's ACCOUNTS table in the database):
PROCEDURE sp_ZapAccounts
	USE accounts EXCLUSIVE
	ZAP

PROCEDURE sp_PackAccounts
	USE accounts EXCLUSIVE
	PACK
Save and close. Also close the database. Note that both PACKing and ZAPping require exclusive access to tables.

Create console C# project (conversion to VB.Net is obvious). Add the following code. Replace Data Source parameter in ConnStr with actual value, the path to your database. If you use VB.Net replace all "\\" with "\".
using System;
using System.Data;
using System.Data.OleDb;

namespace AccessingVFPviaOleDb
{
	class Class1
	{
		[STAThread]
		static void Main(string[] args)
		{
			ZapAccounts();
		}

		static void ZapAccounts()
		{
			string ConnStr = "Provider=vfpoledb.1;" +
					"Data Source=C:\\MYDATA\\TEST.DBC;" +
					"Collating Sequence=machine";

			OleDbConnection cn = new OleDbConnection(ConnStr);

			try
			{
				cn.Open();
				OleDbCommand cmd = new OleDbCommand("sp_ZapAccounts()", cn);
				cmd.ExecuteNonQuery();
			}
			catch (Exception e)
			{
				Console.Write(e.Message);
				return;
			}
			finally
			{
				cn.Close();
			}
		}
	}
}
As you can see, the code creates a OleDb connection to the database and executes a single SQL statement, which is the name of a stored procedure (don't forget to put round brackets).

Hope it helps.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform