While trying to create CDX
file on existing DBF
file using below code, I'm getting an exception saying "No table is open in the current work area"
.
Language - C#
Exception Details -
Message - No table is open in the current work area.
Source - Microsoft OLE DB Provider for Visual FoxPro
Below is code snippet:
public void CreateIndex()
{
var cdxExpressions = new List<CDXExpression> {
new CDXExpression { expression = "ENTRY_DATE", name = "cdx_p1"},
new CDXExpression { expression = "ENTRY_CODE", name = "cdx_p2"},
new CDXExpression { expression = "Month", name = "cdx_p3"},
new CDXExpression { expression = "Year", name = "cdx_p4"},
new CDXExpression { expression = "Company", name = "cdx_p5"}
};
string dbfFile = ConfigurationManager.AppSettings["DBFFileLocation"];
string connectionString = @"Provider=VFPOLEDB.1;Data Source=" + dbfFile + ";Extended Properties=dBASE IV;";
OleDbConnection connection = new OleDbConnection(connectionString);
var queries = DBFQuery.CreateCDXQueries(cdxExpressions, dbfFile);
connection.Open();
try
{
foreach (var qry in queries)
{
OleDbParameter script = new OleDbParameter("script", qry);
OleDbCommand dbfCommand = connection.CreateCommand();
dbfCommand.CommandType = CommandType.StoredProcedure;
dbfCommand.CommandText = "ExecScript";
//dbfCommand.Connection.Open();
dbfCommand.Parameters.Add(script);
dbfCommand.ExecuteNonQuery();
}
}
catch (Exception ex)
{
// I should Open the DBF/Table in the current work area to avoid the exception
}
connection.Close();
}
How to open DBF file in c# to avoid exception "No table is open in the current work area", also using Microsoft OLE DB Provider
for Visual FoxPro