Select from sql with C#

G

Guest

Hi, I have trouble reading from sql database. this select works good
string SQL = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME" and it finds att the tables
in my database.
But then when I try Select * from Employee I get an exception " Invalid
object name Employee." Anya idea why this is happening??
 
N

Nicholas Paldino [.NET/C# MVP]

Lamis,

This would be because you don't have a table or view named Employee in
the database that you are connected to.
 
G

Guest

Hello Nocholas,
In my first Query I do scan all tables in my database and the result shows
that I have a table "Employee". I can see by my SQL manager that I have my
Empolyee table there.

???
--
LZ


Nicholas Paldino said:
Lamis,

This would be because you don't have a table or view named Employee in
the database that you are connected to.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lamis said:
Hi, I have trouble reading from sql database. this select works good
string SQL = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME" and it finds att the
tables
in my database.
But then when I try Select * from Employee I get an exception " Invalid
object name Employee." Anya idea why this is happening??
 
N

Nicholas Paldino [.NET/C# MVP]

Are you sure that the connection string is correct and that you are
connecting to the right data source? Also, what is the type of exception
you are getting?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lamis said:
Hello Nocholas,
In my first Query I do scan all tables in my database and the result shows
that I have a table "Employee". I can see by my SQL manager that I have my
Empolyee table there.

???
--
LZ


Nicholas Paldino said:
Lamis,

This would be because you don't have a table or view named Employee
in
the database that you are connected to.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lamis said:
Hi, I have trouble reading from sql database. this select works good
string SQL = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME" and it finds att the
tables
in my database.
But then when I try Select * from Employee I get an exception " Invalid
object name Employee." Anya idea why this is happening??
 
P

Paul Shapiro

You may need to qualify the tablename in your sql. You didn't see what sql
version. In 2000 you qualify with the owner name. It's usually dbo.Employee.
In SQL 2005 you qualify with the schema name which could be dbo but might
also be a more meaningful schema, like Personnel.Employee.

Lamis said:
Hello Nocholas,
In my first Query I do scan all tables in my database and the result shows
that I have a table "Employee". I can see by my SQL manager that I have my
Empolyee table there.


Nicholas Paldino said:
Lamis,

This would be because you don't have a table or view named Employee
in
the database that you are connected to.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lamis said:
Hi, I have trouble reading from sql database. this select works good
string SQL = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME" and it finds att the
tables
in my database.
But then when I try Select * from Employee I get an exception " Invalid
object name Employee." Anya idea why this is happening??
 
G

Guest

hi Nicholas,

that was it, I had 2000 and needed to qualify with the owner name. Thank
your for your help.
--
LZ


Paul Shapiro said:
You may need to qualify the tablename in your sql. You didn't see what sql
version. In 2000 you qualify with the owner name. It's usually dbo.Employee.
In SQL 2005 you qualify with the schema name which could be dbo but might
also be a more meaningful schema, like Personnel.Employee.

Lamis said:
Hello Nocholas,
In my first Query I do scan all tables in my database and the result shows
that I have a table "Employee". I can see by my SQL manager that I have my
Empolyee table there.


Nicholas Paldino said:
Lamis,

This would be because you don't have a table or view named Employee
in
the database that you are connected to.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi, I have trouble reading from sql database. this select works good
string SQL = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE
TABLE_TYPE = 'BASE TABLE' ORDER BY TABLE_NAME" and it finds att the
tables
in my database.
But then when I try Select * from Employee I get an exception " Invalid
object name Employee." Anya idea why this is happening??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top