tableadapter help needed

delstar

Well-known member
Joined
Jun 9, 2006
Messages
59
Programming Experience
1-3
I'm trying to learn how to use simple SQL databases through .NET. I'm using VB.NET 2005 Express and SQL Server Express. Let me explain what I do and see if you can help me figure out what's missing.

1) I 'Add a new Data Source..' and point it to an empty db that I created in the Management Studio. (testDataSet)

2) I drag a TableAdapter onto the Designer. This creates DataTable1 and starts up the wizard for it.

3) I use the default connection string, select either 'Use SQL Statements' or 'Create new stored procedures' (either way doesn't make a difference), and put in 'SELECT * FROM DataTable1' for my SQL statement. I use the defaults for everything after that. At the end of the wizard, though, it gives the error "Invalid object name 'DataTable1'"

And this is where I'm stuck. Any help would be appreciated.
 
no, it actually doesn't say so. There is nothing even hinting at "My database table is called DataTable1".

If you have called your SQL table this, I would suggest this is probably what is causing your problem, as that is an object name within VS.

I'd rename the table in your SQL, and then in your app, delete your DataSet and start again.

1) In Visual Studio, click the Data Sources tab in the right pane. Click the icon along the top called "Add New DataSource"
2) Connect to a Database, and add the connection unless it appears correctly in the current drop down list.
3) On the "Choose your database objects" screen, expand Tables and tick the table you want to add.
4) Name the dataSet something like dsTest or dsMyDataSet
5) Click Finish

You should now see your dataset and within it a DataTable (called whatever you named it in your SQL database, e.g. Customer)

6) Highlight the dataset and click the button called "Edit DataSet with Designer"
7) You should see your table here. Right click the header and select "Configure"
8) Now you will see the SQL used to retrieve all the data. Click Next.
9) This is the methods screen. This is the name of the Fill and Get commands, normally if you are filling ALL rows, the default values are fine. Click Next.
10) Hopefully the Wizard results will have ticked all, and you will have SELECT, INSERT, UPDATE, DELETE commands, table mappings, Fill method, Get method and Update methods. Click Finish


Now on your form, to create a quick DataGridView of the table, drag the table expanded from the dataset on the Data Sources tab onto your form. This will also automatically add the .Fill command and the necessary objects to your form.

Press F5 to test.


Good luck :)
 
Look at my Step 2 again.

2) I drag a TableAdapter onto the Designer. This creates DataTable1 and starts up the wizard for it.

I have also already tried renaming the table. Same error.
 
OK, figured it out. Apparently the fact that it didn't have any tables confused it. I had to create the through the Database Explorer instead of the Designer.
 
I'm trying to learn how to use simple SQL databases through .NET. I'm using VB.NET 2005 Express and SQL Server Express. Let me explain what I do and see if you can help me figure out what's missing.

1) I 'Add a new Data Source..' and point it to an empty db that I created in the Management Studio. (testDataSet)
What what?
Management Studio as in SQL Server Management Studio? So youre definitely making database tables, yeah? Youre not doing this in the Visual Studio IDE are you? Are you sure? VS cannot make database tables (last i knew of anyway) without manually writing the CREATE TABLE SQLs yourself

See what is confusing is that you have chosen to create a DB and call it testDataSet. Dont do that.. thats just gonna confuse us. DataSets are the client side temporary data storage containers that you download database data into. Dont call your database that, because that's just silly, and confsing for other developers in the same way that calling a cupboard a dishwasher is going to confuse your kid when you tell it to put its dirty plate in the dishwasher

2) I drag a TableAdapter onto the Designer. This creates DataTable1 and starts up the wizard for it.
Again, confusing. You dont drag table adapters anywhere; they are created by the IDE when you drag a database table out of the server explorer onto the dataset surface designer. Noone ever, EVER can drag a tableadapter into a dataset becuse they simply DONT EXIST outside of a dataset to be dragged into it.

3) I use the default connection string, select either 'Use SQL Statements' or 'Create new stored procedures' (either way doesn't make a difference), and put in 'SELECT * FROM DataTable1' for my SQL statement. I use the defaults for everything after that. At the end of the wizard, though, it gives the error "Invalid object name 'DataTable1'"
Confusion confusion. DataTables are client side objects, and again, unless you took the silly step of calling a table in your database "DataTable1" then there is nothing there for you to select from. I think you need to stop guessing and follow a good walkthrough. The DW2 link in my sig, section on Creating a Simple Data App - do that. If it says download the exaple Northwind databases, then yep, do that too
Do it all exactly per the walkthrough, then youll know what youre doing and we can help more easily

And call a spade a spade in future! :)
 
OK, figured it out. Apparently the fact that it didn't have any tables confused it. I had to create the through the Database Explorer instead of the Designer.

More like the fact that you didnt create any database tables, thought that a dataset was a database and the dataset designer was for creating database tables, and then asked us questions as though you'd called your database tables names that would normally be attributed to client side datastorage containers confused everybody.. I can see how it's an easy mistake to make though.. I remember doing it myself, kinda ;)
Apart form the IDE of course; it didnt get confused, because what you were asking it do wasnt possible..
 
Back
Top