我尝试使用以下代码将分隔文本附加到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)
答案 0 :(得分:1)
虽然您现有的代码存在问题,但我认为通过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);
}
}