gpt4 book ai didi

c# - 在 C# 中从 VFP OLEDB 追加时出错

转载 作者:太空宇宙 更新时间:2023-11-03 12:57:58 25 4
gpt4 key购买 nike

我尝试使用以下代码将分隔文本附加到 Fox 表:

OleDbConnection oledbConn = new OleDbConnection(String.Format(@"Provider=VFPOLEDB.1;Data Source={0};Collating Sequence=MACHINE", Inputpath + "UnRepWor.dbf"));
OleDbCommand oledbComm = new OleDbCommand { Connection = oledbConn, CommandType = CommandType.Text };

string insertCammand = String.Format(@"APPEND FROM {0} DELIMITED WITH TAB", @"'d:\TestServiceOutput\data.dat'");
oledbComm.CommandText = insertCammand.Trim();
try
{
oledbConn.Open();
oledbComm.ExecuteNonQuery();
}
catch (Exception ex)
{
throw Utility.GetExceptionDetails(ex, "WordRootFoxExportServiceDataAccessLayer - ImportToFoxTable- insert into Fox Table",ex.Message);
}

并得到这个错误:

Message = "One or more errors occurred during processing of command."
Source = "Microsoft OLE DB Provider for Visual FoxPro"
ErrorCode = -2147217900
ex.StackTrace :
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)

最佳答案

虽然您现有的代码有问题,但我认为 VFPOLEDB 不直接支持 Append from。相反,您可以这样尝试:

string vfpScript = string.Format(@"
use UnRepWor shared
APPEND FROM ('{0}') DELIMITED WITH TAB
use", @"d:\TestServiceOutput\data.dat");

using (OleDbConnection oledbConn = new OleDbConnection(String.Format(@"Provider=VFPOLEDB.1;Data Source={0};Collating Sequence=MACHINE", Inputpath)))
{
OleDbCommand oledbComm = new OleDbCommand {
Connection = oledbConn,
CommandType = CommandType.StoredProcedure,
CommandText="ExecScript" };
oledbComm.Parameters.AddWithValue("code", vfpScript);

try
{
oledbConn.Open();
oledbComm.ExecuteNonQuery();
}
catch (Exception ex)
{
throw Utility.GetExceptionDetails(ex,
"WordRootFoxExportServiceDataAccessLayer - ImportToFoxTable- insert into Fox Table",
ex.Message);
}
}

关于c# - 在 C# 中从 VFP OLEDB 追加时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33251982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com