Narasiman nar

Narasiman nar

  • NA
  • 64
  • 20.2k

fill selectcommand.connection property has not beeninitializ

Jun 8 2018 1:15 AM
fill selectcommand.connection property has not been initialized
  1. if (e.CommandName == "UploadFarmData")  
  2. {  
  3. string CurrentFilePath = Path.GetFullPath(FileUpload1.PostedFile.FileName);  
  4. constr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES;""", CurrentFilePath);  
  5. Econ = new OleDbConnection(constr);  
  6. Econ.Open();  
  7. DataTable dtExcelSchema;  
  8. dtExcelSchema = Econ.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);  
  9. string sheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();  
  10. DataSet ds = new DataSet();  
  11. string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();  
  12. OleDbCommand cmdExcel = new OleDbCommand();  
  13. OleDbDataAdapter da = new OleDbDataAdapter();  
  14. cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";  
  15. da.SelectCommand = cmdExcel;  
  16. da.Fill(ds);  
  17. Econ.Close();  
  18. DataTable dt = new DataTable();  
  19. dt = ds.Tables[0];  
  20. bool s = false;  
  21. if (dt.Rows.Count > 0)  
  22. {  
  23. for (int i = 0; i < dt.Rows.Count; i++)  
  24. {  
  25. dal.DAL_Insert_Farm_Data(dt.Rows[i]["Farmer Code"].ToString(), dt.Rows[i]["Farm No"].ToString(),  
  26. dt.Rows[i]["Type of Farm"].ToString(), dt.Rows[i]["Seeded Date"].ToString(), dt.Rows[i]["Farm Visit No"].ToString());  
  27. s = true;  
  28. }  
  29. if (s)  
  30. {  
  31. showStatusTrue.InnerHtml = "Farm Details Uploaded Successfully";  
  32. dal.DAL_Data_Update();  
  33. }  
when run the above shows error as follows
 
fill selectcommand.connection property has not been initialized
 
how to fix this error. please let me know.

Answers (1)