Javi
Javi

Reputation: 81

OleDbDataAdapter: Check table existence?

I have a program in C# that works with .xls files, where I query the database as below:

SELECT * FROM [" +sheet + "$]

If the sheet doesn't exist, the program crashes.

I need to first check if the table exists and if so, make some queries.

Is there any such option for OleDbDataAdapter or SQL when querying with SELECT, INSERT, UPDATE or DELETE?

Upvotes: 0

Views: 1829

Answers (2)

Andrew Hanlon
Andrew Hanlon

Reputation: 7451

Use the GetOleDbSchemaTable function. It's a bit obscure, but here's a link or two to some info:

http://www.codeproject.com/Questions/180842/Reading-Excel-sheet-name-with-characters.aspx?display=PrintAll

http://support.microsoft.com/kb/318452

Upvotes: 1

TcKs
TcKs

Reputation: 26642

You can check shema (tables, views, etc...) via Connection.GetSchema - http://msdn.microsoft.com/en-us/library/ms254934%28v=vs.80%29.aspx

Upvotes: 0

Related Questions