当前工作区域中未打开任何表 [英] No table is open in the current work area
本文介绍了当前工作区域中未打开任何表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当尝试使用下面的代码在现有DBF
文件上创建CDX
文件时,出现一个异常,提示"No table is open in the current work area"
.
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"
.
语言-C#
异常详细信息-
Message - No table is open in the current work area.
Source - Microsoft OLE DB Provider for Visual FoxPro
下面是代码段:
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();
}
如何在c#中打开DBF文件以避免出现异常当前工作区中没有表打开",也对Visual FoxPro
使用Microsoft OLE DB Provider
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
推荐答案
这个与CDXExpression列表一起存在:
This one is with your CDXExpression list:
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"}
};
var myCode = "use sample exclusive\n" +
string.Join("\n", cdxExpressions.Select(e => $"index on {e.expression} tag {e.name}")) +
"\nuse";
string dbfFile = ConfigurationManager.AppSettings["DBFFileLocation"];
string connectionString = @"Provider=VFPOLEDB;Data Source=" + dbfFile;
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand cmd = connection.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "ExecScript";
OleDbParameter parm = cmd.CreateParameter();
parm.OleDbType = OleDbType.Char;
cmd.Parameters.Add(parm);
parm.Value = myCode;
try
{
connection.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
// ...
}
}
}
这篇关于当前工作区域中未打开任何表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文