Click here to Skip to main content
15,877,637 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
string path = Server.MapPath("~/myfolder/myfile.xlsx");
string connExcel= "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0;HDR=NO;IMEX=1\";";
 connExcel.Open();
            DataTable dtExcelSchema;
            dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
            string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
            connExcel.Close();
sting query ="Select * From [" + SheetName + "]";
Posted
Updated 29-Apr-15 3:04am
v4
Comments
ZurdoDev 29-Apr-15 8:22am    
What is the value of SheetName?
Sinisa Hajnal 29-Apr-15 8:59am    
Check the values you get, both in dtExcelSchema, number of rows, sheetName etc..

Replace:
C#
sting query ="Select * From [" + SheetName + "]";

with:
SQL
sting query =@"Select * From [" + SheetName + "$]";


For further information, please see:
http://www.connectionstrings.com/excel/[^]
Accessing Microsoft Office Data from .NET Applications[^] - note that some piece of information is obsolete.
 
Share this answer
 
v2
thanks to all for this regard
please tell me one more query
i am making a excelfile xyz from datatable dt but its have converted all datatypes.
datatable dt => excel file xyz
i Have to create a txtbox to read excelfile xyz query.
txt.text = "Select * from["+sheetname+"$] where col>9";
how to do??????
col(string) =>col(decimal)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900