473,661 Members | 2,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlDataAdapter. Fill() : Invalid object name <TableName>

I'm trying to build a basic DB explorer using C# & Visual Studio 2005. I
installed SQL Server 2005 Express, created a blank project, dropped a
TreeView, a ListView and a DataGridView : DB objects (Databases, tables,
SPs, and so on) are displayed in the tree, table colums definitions in
the list and I want to display the selected table content in the
DataGridView. So far so good. Currently, I succedded in loading the
treeview and the listview but I CAN'T connect the DataGridView with my
database in order to make it display a table content !!

The same exception is ALWAYS raised by the Fill() method of a
SqlDataAdapter I create to build the view :

sqlAdapter.Fill (dataTable): Unhandled SQL exception: Invalid object name
<TableName>
(The original message, in French, is "Nom d'objet '<TableName>' non
valide.").

<TableNamecan be replaced by every table I have in my server, I
checked with a database I created (Database TEST, Table TABLE1) and with
system databases like tempdb, master, or msdb) without any success.

I'm puzzled. I tried to prefix the table names by their schema or their
parent database name, but the exception is still raised.

Here is my code :
public void fillDataGrid(Da taGridView inGridView,
string inSelectCommand )
{
/* Vérifier qu'on est connecté */
checkConnected( );

inGridView.Auto GenerateColumns = true;

inGridView.Auto ResizeColumns(D ataGridViewAuto SizeColumnsMode .AllCellsExcept Header);

DataTable dataTable = new DataTable();
SqlCommand sqlCommand = new SqlCommand(inSe lectCommand,
sqlConnection_) ;

/* Remplir la vue */
SqlDataAdapter sqlAdapter = new SqlDataAdapter( sqlCommand);
sqlAdapter.Fill (dataTable);

inGridView.Data Source = dataTable;

}

"inSelectComman d" can be "SELECT * FROM Table1", "SELECT * FROM
TEST.TABLE1" (using the parent DB name), or "SELECT * from dbo.TABLE1"
(using the owner's name), for instance; the exception is always raised.

My connection string :
- doesn't provide a startup database since I've to be able to explore
them all
- Use "tcp:(local ), 1025" or "DOMAIN\USE R" to specify my local
computer (I'm running XP SP2 with admin rights)
- Use "Integrated Security = True" to use the Windows integrated
security.

Any hint greatly appreciated !

Best regards,

A.R.
Jan 27 '07 #1
2 16851
Adrien,

This probably may be happening because of your database connection, which
probably is not pointing to the right DB. Try this:

SELECT * FROM databasename.ow ner.yourtablena me

using the information you gave us:

SELECT * FROM TEST.dbo.TABLE1

Since you don't list here the code to connect to the database, verify the
database connection.

Does it work now?

--
Regards,
Robson Siqueira
Enterprise Architect
"Adrien Reboisson" <ad************ *************** *@nospam.comwro te in
message news:uQ******** ******@TK2MSFTN GP03.phx.gbl...
I'm trying to build a basic DB explorer using C# & Visual Studio 2005. I
installed SQL Server 2005 Express, created a blank project, dropped a
TreeView, a ListView and a DataGridView : DB objects (Databases, tables,
SPs, and so on) are displayed in the tree, table colums definitions in the
list and I want to display the selected table content in the DataGridView.
So far so good. Currently, I succedded in loading the treeview and the
listview but I CAN'T connect the DataGridView with my database in order to
make it display a table content !!

The same exception is ALWAYS raised by the Fill() method of a
SqlDataAdapter I create to build the view :

sqlAdapter.Fill (dataTable): Unhandled SQL exception: Invalid object name
<TableName>
(The original message, in French, is "Nom d'objet '<TableName>' non
valide.").

<TableNamecan be replaced by every table I have in my server, I checked
with a database I created (Database TEST, Table TABLE1) and with system
databases like tempdb, master, or msdb) without any success.

I'm puzzled. I tried to prefix the table names by their schema or their
parent database name, but the exception is still raised.

Here is my code :
public void fillDataGrid(Da taGridView inGridView,
string inSelectCommand )
{
/* Vérifier qu'on est connecté */
checkConnected( );

inGridView.Auto GenerateColumns = true;

inGridView.Auto ResizeColumns(D ataGridViewAuto SizeColumnsMode .AllCellsExcept Header);

DataTable dataTable = new DataTable();
SqlCommand sqlCommand = new SqlCommand(inSe lectCommand,
sqlConnection_) ;

/* Remplir la vue */
SqlDataAdapter sqlAdapter = new SqlDataAdapter( sqlCommand);
sqlAdapter.Fill (dataTable);

inGridView.Data Source = dataTable;

}

"inSelectComman d" can be "SELECT * FROM Table1", "SELECT * FROM
TEST.TABLE1" (using the parent DB name), or "SELECT * from dbo.TABLE1"
(using the owner's name), for instance; the exception is always raised.

My connection string :
- doesn't provide a startup database since I've to be able to explore
them all
- Use "tcp:(local ), 1025" or "DOMAIN\USE R" to specify my local computer
(I'm running XP SP2 with admin rights)
- Use "Integrated Security = True" to use the Windows integrated
security.

Any hint greatly appreciated !

Best regards,

A.R.

Jan 27 '07 #2
Robson Siqueira a écrit :
SELECT * FROM databasename.ow ner.yourtablena me

Does it work now?
Yes. Thank you very much Robson, you saved my week end ;-)

Cheers from France !

A.R.
Jan 28 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
2708
by: jason | last post by:
Hi Ray...a while ago you explained an elegant solution to enable me to CREATE and EDIT existing tables and queries inside my online access 2000 database.... could you provide refresher links on this or possibly some starter code? I am just so sick of the syncronization problems that come into play when you adjust underlying tables and queries offline and then have to overwrite the live database? Many thanks Jason
2
96833
by: Dave Moore | last post by:
Hi, I want to use CSS to define the font size in every cell of a table. This avoids needing to define the font size in every <TD> tag using the normal multiple HTML <FONT SIZE="2"> notation. Therefore my question is, Is there a CSS attribute I can set on the <TD> tag that will set the size of any text within the table cell?. Regards, Dave
1
2684
by: Ed Bacon | last post by:
I am trying to produce a generic "audit report" for various transactions in our application. Each transaction type defines a document (and has an associated schema). When a transaction leads to a "write to the database", we store the dataset's diffgram in the audit table. To render the audit report we load the diffgram into a generic DataSet and bind it to a grid. All works well unless the document's schema had an <xs:import> to bring...
6
14903
by: Marcel Hug | last post by:
Hi all ! I have a table in my database, which has 3 attributes. IDFailureControl, ControlDate and ControlVersion. In the following function I test, if the date of today allready exists. Then I would like to write the new ControlDate or Version into the database. First i update the dataset, then i create a Insertcommand and call the update-methode. All datas are in the database, but.... 1.) If I only use the InsertCommand, without...
2
2893
by: weird0 | last post by:
I am testing a webservice locally that connects to BankingDb and check the function public bool CheckPincode(string Pincode) { SqlConnection sqlConnection1 =new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("SELECT acc_pincode FROM
0
2417
by: sphinney | last post by:
I have a complex Access 2002 database with multimple tables, queries, forms, and reports. The database is used by miltiple users that have one of four different levels of security. The databae uses a workgroup security file. The database is designed to be opened without the workgroup security file by general users (who have the lowest permission levels). I've been working on the database recently to make some "minor" modifactions. ...
0
1071
by: Icemokka | last post by:
Hi all, We have 2 databases that are not connected to each other directly. Changes to either databases can only be done on one side. Those 2 databases are of the type MSAccess or MSSQL but with the same structure. So if something changes ( added,updated,deleted ) in Database 1 this should be replicated through a webservice to Database 2. I was thinking to make a kind of sourcesafe where you can check-in &
3
3479
oll3i
by: oll3i | last post by:
package ejb; import javax.ejb.EJBObject; import java.rmi.RemoteException; import java.sql.Connection; import java.util.Map; public interface InterfaceRemote extends EJBObject { public Map <String,String> returnTable(String tableName) throws RemoteException; Connection getConnection()throws RemoteException; public int getNumberOfColumns(String tableName)throws RemoteException; }
5
2776
by: matt | last post by:
This is a strange one but I've been stuck on it for days. Any help appreciated. THE PLAN: I've a database that I use a script to grab all the entries for a particular field. I then want to send each of these entries individually to another server using fputs. The server will send 1 response (a lin of text) back for each item
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.