943,810 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1531
  • VB.NET RSS
Feb 10th, 2009
1

Invalid Object error, yet Table already created.

Expand Post »
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:

VB.NET Syntax (Toggle Plain Text)
  1. Dim vCustomer, vBulkQty, vItem, vBaseUnit, vEachQty, vEachUnit As String
  2.  
  3. vCustomer = dgCustomers.CurrentRow.Cells(0).Value
  4. vItem = dgItems.CurrentRow.Cells(0).Value
  5. vBulkQty = dgItems.CurrentRow.Cells(3).Value
  6. vBaseUnit = dgItems.CurrentRow.Cells(4).Value
  7. vEachQty = dgItems.CurrentRow.Cells(5).Value
  8. vEachUnit = dgItems.CurrentRow.Cells(6).Value
  9.  
  10. Dim Insert As String
  11.  
  12. Insert = "INSERT INTO OTM_ORDERS(CustomerID,ItemNo,BulkQty,BaseUnit,EachQty,StockUnit) " _
  13. & "VALUES ('" & Trim(vCustomer) & "','" & Trim(vItem) & "','" & Trim(vBulkQty) & "','" _
  14. & Trim(vBaseUnit) & "','" & Trim(vEachQty) & "','" & Trim(vEachUnit) & "')"
  15.  
  16. Dim sqlCom As New SqlCommand(Insert, conn)
  17. 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?
Last edited by bajanpoet; Feb 10th, 2009 at 4:01 pm. Reason: these damn code tags.... argh
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bajanpoet is offline Offline
96 posts
since Sep 2006
Feb 13th, 2009
0

Re: Invalid Object error, yet Table already created.

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

Cheers
Reputation Points: 11
Solved Threads: 9
Light Poster
Rogachev is offline Offline
44 posts
since Nov 2008
Feb 13th, 2009
0

Re: Invalid Object error, yet Table already created.

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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bajanpoet is offline Offline
96 posts
since Sep 2006
Feb 13th, 2009
0

Re: Invalid Object error, yet Table already created.

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...
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
bajanpoet is offline Offline
96 posts
since Sep 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Barcode basics
Next Thread in VB.NET Forum Timeline: VB Array values





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC