public DataTable Showdataprint() { 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); OleDbConnection con = new OleDbConnection(connectionString); con.Open(); DataTable dt = new DataTable(); dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string SheetName = dt.Rows[0]["TABLE_NAME"].ToString(); OleDbCommand com = new OleDbCommand(); com.Connection = con; //com.CommandText = @"SELECT CStr([رقم الاستمارة]) as [UnitCode],[قراءة العداد]as[CurrentMeterReading] FROM [" + SheetName + "] "; com.CommandText = @"SELECT [رقم الاستمارة] as [UnitCode],[رقم العدا د]as[CounterNumber],[قراءة العداد]as[CurrentMeterReading] FROM [" + SheetName + "] "; OleDbDataAdapter oledbda = new OleDbDataAdapter(); oledbda.SelectCommand = com; DataSet ds = new DataSet(); oledbda.Fill(ds); dt = ds.Tables[0]; con.Close(); return dt; }
when selecting data from excel sheet and columns name alias different give error
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)