Oledb Exception - 没有给出一个或多个必需参数的值

时间:2013-09-06 04:51:10

标签: c# asp.net

我试图在asp.net c#中使用Microsoft.Jet.OLEDB.4.0读取一个csv文件,但是我收到的错误是“没有给出一个或多个必需参数的值。”

my select query :

string query = string.Concat("SELECT a_id, EpisodeId, Logged, [appintmentfollowporreferral] as Appointment, AppointmentType, AppointmentDateAndTime, AppointmentWith, Outcome, RTWStatus, Completed FROM " + appointmentReportsFileName);

here is the code that i am using to read the csv file :

string connString = string.Concat("Provider=Microsoft.Jet.OLEDB.4.0;", "Data Source=", filePath, ";", "Extended Properties=\"text;HDR=Yes;FMT=D=Delimited(,)\"");
            //create an OleDbDataAdapter to execute the query
            OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
            //fill the DataTable
            dAdapter.Fill(dTable);
            dAdapter.Dispose();

该文件包含查询字符串中指定的所有列名,我检查了列名称是否有任何差异,但我找不到任何区别。

这是我想读的csv文件:


请帮助我解决这个问题......

1 个答案:

答案 0 :(得分:0)

放置列名称

e.g。

string query = string.Concat("SELECT [a_id], EpisodeId, [Logged], 
[appintmentfollowporreferral] as [Appointment], AppointmentType, AppointmentDateAndTime,
AppointmentWith, [Outcome], RTWStatus, Completed FROM " + appointmentReportsFileName);

同时检查是否存在所有给定列或表名变量(appointmentReportsFileName)是否具有有效值