Invalid Object error, yet Table already created.

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2006
Posts: 88
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Invalid Object error, yet Table already created.

 
0
  #1
Feb 10th, 2009
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:

  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 16
Reputation: Rogachev is an unknown quantity at this point 
Solved Threads: 2
Rogachev Rogachev is offline Offline
Newbie Poster

Re: Invalid Object error, yet Table already created.

 
0
  #2
Feb 13th, 2009
Hello.
Can you show which do you use connection string with your database? Please ensure your connection string is correct.

Cheers
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 88
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Re: Invalid Object error, yet Table already created.

 
0
  #3
Feb 13th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 88
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Re: Invalid Object error, yet Table already created.

 
0
  #4
Feb 13th, 2009
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...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC