954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Invalid Object error, yet Table already created.

I'm trying to use VB.NET to insert the data in the current row of my datagrid into a table. I wrote the following code:

Dim vCustomer, vBulkQty, vItem, vBaseUnit, vEachQty, vEachUnit As String
       
        vCustomer = dgCustomers.CurrentRow.Cells(0).Value
        vItem = dgItems.CurrentRow.Cells(0).Value
        vBulkQty = dgItems.CurrentRow.Cells(3).Value
        vBaseUnit = dgItems.CurrentRow.Cells(4).Value
        vEachQty = dgItems.CurrentRow.Cells(5).Value
        vEachUnit = dgItems.CurrentRow.Cells(6).Value

        Dim Insert As String

        Insert = "INSERT INTO OTM_ORDERS(CustomerID,ItemNo,BulkQty,BaseUnit,EachQty,StockUnit) " _
        & "VALUES ('" & Trim(vCustomer) & "','" & Trim(vItem) & "','" & Trim(vBulkQty) & "','" _
        & Trim(vBaseUnit) & "','" & Trim(vEachQty) & "','" & Trim(vEachUnit) & "')"

        Dim sqlCom As New SqlCommand(Insert, conn)
        sqlCom.ExecuteNonQuery()


The problem is that although there doesn't seem to be anything wrong with the code I get an unhandled SQLException on the sqlCom.ExecuteNonQuery() statement that says "Invalid object name 'OTM_ORDERS'."

I've already created this table using SQL, so why am I not able to insert data into it?

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Hello.
Can you show which do you use connection string with your database? Please ensure your connection string is correct.

Cheers

Rogachev
Light Poster
44 posts since Nov 2008
Reputation Points: 11
Solved Threads: 9
 

The connection string is correct. I can pull information from the same database and display it - I am trying to save the information taken from one table into a newly created table.

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

Just to let you know, everyone, that the code was correct. When I ran the code to create the table, it was created on the wrong server... so when I ran it, the application was looking for the created table on the wrong server. It's working as expected now.

Sorry for any inconvenience...

bajanpoet
Junior Poster in Training
96 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You