Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
Hello Team,

I am getting the Data from Entity.
I want the column Name From Excel in C#.I wrote the Method as Follows .

C#
private static string[] GetColumnRangeForExcel(IFileLog fileLog)

    {
string[] townNameArray = null;

if (fileLog.FileName) //// Error 245 Cannot implicitly convert type 'string' to 'bool'

{

            townNameArray = "select Town Name from [" + fileLog.FileName + "$]";
            //// Error  246 Cannot implicitly convert type 'string' to 'string[]'

          }
}


its give me error as shown above.Please Guide me how to solve it ??



Thanks
Harshal
Posted
Updated 5-Aug-14 1:30am
v5

1 solution

Try:
SQL
SELECT * FROM [Sheet1$A1:A65536]

or
SQL
SELECT [F1] FROM [Sheet1$]

or
SQL
SELECT [NamedColumn] FROM [Sheet1$]


More: How To Use ADO with Excel Data from Visual Basic or VBA[^]
 
Share this answer
 
v2
Comments
R Harshal 4-Aug-14 10:14am    
I have a excel sheet name as follows:
WCEL_DBBH_REPORT_MASTER_HAR_20140803.xls .
In this excel sheet there are 256 columns .I want to select only the last column that is 256 (namely:xyz )
My query will be like
SELECT [xyz] FROM [WCEL_DBBH_REPORT_MASTER_HAR_20140803.xls$]
Is that so .Please let me know.

Thanks
Harshal
Maciej Los 4-Aug-14 10:18am    
You need to properly set connection string to workbook: WCEL_DBBH_REPORT_MASTER_HAR_20140803.xls, then you'll be able to fetch data from the Sheet.
R Harshal 4-Aug-14 10:20am    
what I need is

sql_query(Query as String;ChosenRange as Range)

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