ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 275.4k

error no value given for one or more required parameters.'

Apr 21 2018 4:40 AM
When i try to get data from excel sheet i get error
 
no value given for one or more required parameters.'
 
why this happen
 
i work in visual studio 2010 with excelsheet 2013
 
my code in c# as following
  1. public DataTable ShowWrongExcelData()  
  2.   
  3.            {  
  4.   
  5.                string connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";", txtPath.Text);  
  6.                OleDbConnection con = new OleDbConnection(connectionString);
  7.                con.Open();  
  8.   
  9.                string str = @"SELECT  [??? ?????????] as [UnitCode],[????? ??????]as[CurrentMeterReading] FROM  [Sheet5$] where [CurrentMeterReading] <= 0 ";
  10.                OleDbCommand com = new OleDbCommand();
  11.                com = new OleDbCommand(str, con);
  12.                OleDbDataAdapter oledbda = new OleDbDataAdapter();
  13.                oledbda = new OleDbDataAdapter(com);
  14.                DataSet ds = new DataSet();
  15.                ds = new DataSet();
  16.                oledbda.Fill(ds, "[Sheet5$]");
  17.                con.Close();
  18.                System.Data.DataTable dt = new System.Data.DataTable();
  19.                dt = ds.Tables["[Sheet5$]"];
  20.                return dt;
  21.            } 
 why give this error i dont use any parameters

but when i select all data from Excel sheet as following :

@"SELECT [??? ?????????] as [UnitCode],[????? ??????]as[CurrentMeterReading] FROM [Sheet5$]";

I get data without anyh problem

so that How to solve this error please ?

Excel sheet InvoiceData.xlsx sample

http://www.mediafire.com/file/b62b5ub26mrt9t1/InvoiceData.xlsx
 

Answers (3)