Hi,

Can anyone see where I've gone wrong with this Update? First I want to locate the last row added to my table, after locating the MaxID I want to update another field (SerialNum) with another incremental value.


Dim sSQL1 = New SqlCommand("SELECT MAX(ID) FROM CusCushionInv", cnnCushions)
Dim intMaxID As Integer
Dim daID As New SqlDataAdapter(sSQL1)
Dim dsID As New DataSet()
daID.Fill(dsID, "CusCushionInv")
intMaxID = dsID.Tables("CusCushionInv").Rows(0).Item(0)

So far so good to this point intMaxID reveives the correct value.

Dim strMaxSerial As String
strMaxSerial = "LC000001"
Dim myDataSet As New DataSet()

Dim myCommand = New SqlCommand("cusSP_SerialNum", cnnCushions)
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.Add("@Serial", strMaxSerial)
myCommand.Parameters.Add("@MaxID", intMaxID)
Dim mySqlDataAdapter As New SqlDataAdapter()
mySqlDataAdapter.UpdateCommand = myCommand

mySqlDataAdapter.Update(myDataSet, "CusCushionInv")
myCommand.ExecuteNonQuery()


When I try to run this code I receive this error message:

An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: Update unable to find TableMapping['CusCushionInv'] or DataTable 'CusCushionInv'.


In the Watch window I can see that myDataSet does not get filled but I can't see why not.


This is the stored procedure cusSP_SerialNum:

CREATE PROCEDURE cusSP_SerialNum
@Serial as varchar(20),
@MaxID as integer
AS
UPDATE CusCushionInv Set SerialNum = @Serial
WHERE ID = @MaxID
GO


Can anyone please tell me what they see wrong with this code? Thanks,
Corinne