Click here to Skip to main content
15,073,911 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hi,

I am using the following code to read excel sheets of excel workbook

OleDbDataAdapter command1 = new OleDbDataAdapter("Select * From [" + listSheetNames[0] + "]", connection);<br />
OleDbDataAdapter command2 = new OleDbDataAdapter("Select * From [" + listSheetNames[1] + "]", connection);<br />
OleDbDataAdapter command3 = new OleDbDataAdapter("Select * From [" + listSheetNames[2] + "]", connection);


Right now there are only 3 excel sheets.

I need to write the code in a way that if listSheetNames[3] is available then do something

I am trying some thing like below

if (listSheetNames[3] == "orange")<br />
                {<br />
 command4 = new OleDbDataAdapter("Select * From [" + listSheetNames[3] + "]", connection);<br />
                    command4.Fill(dataSet4);<br />
                    lstDS.Add(dataSet4);<br />
                }


But it is not working

Can any one help me in solving this???

Thanks
John
Posted
Updated 11-Dec-13 1:22am
v2

Hi,

Initially you should have asked Google for this.
It answered my your question for me.
You could find your solution here[^].

Hope this helps you a bit.

Regards,
RK
   
Have as look at the article: How To Retrieve Schema Information by Using GetOleDbSchemaTable and Visual C# .NET under the section titled: "Create Sample That List Tables in a Database".

Be advised that the table names (worksheet names) have a post-pended "$" on them (Sheet1 becomes Sheet1$).

There should be enough information in that example for you to solve your problem, but if you need more guidance, just ask.
   
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



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