locked
TableAdapter help RRS feed

  • Question

  •  

    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.

    Thursday, September 6, 2007 3:48 PM

Answers

  • Hi Delstar,

     

    I reproduced the error.

    The error "Invalid object name 'DataTable1'" indicates the table does not exist in the database mentioned in the connection string.

     

    When you drag a TableAdapter onto the Designer, actually that DataTable1 is created like this:

    The TableAdapter executes queries from database and then returns a new data table named DataTable1.

     

    Thus you should executes queries from database table (not from DataTable1) to return the DataTable1. (Please ensure that your database “testDataSet” has at least one table.)

    e.g.

    SELECT * FROM testDataSet.dbo. myTable1

    Note: once finishing the wizard, the DataTable1 will be renamed as myTable1 automatically.

     

    TableAdapter Overview

    http://msdn2.microsoft.com/en-us/library/bz9tthwx(VS.80).aspx

    TableAdapters is used to provide communication between your application and a database. More specifically, a TableAdapter connects to a database, executes queries or stored procedures, and either returns a new data table populated with the returned data or fills an existing DataTable with the returned data. TableAdapters are also used to send updated data from your application back to the database.

     

    This thread is helpful to you.

    Create DataTable manualy & add to database

     

    Regards,

    Martin

    Monday, September 10, 2007 9:17 AM

All replies

  • Hi Delstar,

     

    I reproduced the error.

    The error "Invalid object name 'DataTable1'" indicates the table does not exist in the database mentioned in the connection string.

     

    When you drag a TableAdapter onto the Designer, actually that DataTable1 is created like this:

    The TableAdapter executes queries from database and then returns a new data table named DataTable1.

     

    Thus you should executes queries from database table (not from DataTable1) to return the DataTable1. (Please ensure that your database “testDataSet” has at least one table.)

    e.g.

    SELECT * FROM testDataSet.dbo. myTable1

    Note: once finishing the wizard, the DataTable1 will be renamed as myTable1 automatically.

     

    TableAdapter Overview

    http://msdn2.microsoft.com/en-us/library/bz9tthwx(VS.80).aspx

    TableAdapters is used to provide communication between your application and a database. More specifically, a TableAdapter connects to a database, executes queries or stored procedures, and either returns a new data table populated with the returned data or fills an existing DataTable with the returned data. TableAdapters are also used to send updated data from your application back to the database.

     

    This thread is helpful to you.

    Create DataTable manualy & add to database

     

    Regards,

    Martin

    Monday, September 10, 2007 9:17 AM
  • Yeah, I figured out later that day. I actually ended up using the Database Explorer to create the tables, and that worked out fine. As soon as I dragged it over, it created the table adapter and everything for me.

     

    Monday, September 10, 2007 2:13 PM
  • Hi Delstar,

     

    Thank you for so quick feedback!

    I'm glad to hear that it works. Cheers!

     

    If you have any difficulties in future developing, please feel free to come back.

     

    Best wishes,

    Martin

    Tuesday, September 11, 2007 1:21 AM