Results 1 to 3 of 3

Thread: Update Command

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    93

    Update Command

    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

  2. #2
    Lively Member
    Join Date
    Mar 2000
    Location
    Fort Lauderdale, FL USA
    Posts
    112
    Sure, you're trying to fill a dataset from a stored procedure that doesn't return any values. Remove the code for the mySqlDataAdapter object and you'll be fine.
    Damonous

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2003
    Posts
    93
    damonous,

    Thanks for the reply. Everythign works fine now.

    Corinne

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width