netdis
netdis

Reputation: 323

SQL command returns invalid object name database.table

I run this code:

                    SqlConnection polaczenie;
                    polaczenie = new SqlConnection(dane_polaczenia);
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = polaczenie;
                    polaczenie.Open();
                    cmd.CommandText = @"SELECT * FROM test.test";
                    cmd.ExecuteNonQuery();

After executing I got exception Invalid object name 'test.test'.

Database and table values are correct.

How to specify database.table in CommandText correctly?

Upvotes: 1

Views: 2204

Answers (1)

RichardTheKiwi
RichardTheKiwi

Reputation: 107716

                cmd.CommandText = @"SELECT * FROM test.dbo.test";

or

                cmd.CommandText = @"SELECT * FROM test..test";

Upvotes: 1

Related Questions