Trying to add a record??

Discussion in 'ASP .Net Web Services' started by dave, Dec 22, 2003.

  1. dave

    dave Guest

    Sub upDateTheWeb()
    Dim MachID = Session("selectedMachineID")
    Dim owebservice As New localhost.updateMachine
    Dim myDS As New DataSet
    Dim myTable As DataTable = myDS.Tables("InventoryRecord")
    Dim newRow As DataRow = myTable.NewRow() '****************************************ERROR
    newRow("machine") = machine.Text
    newRow("SERIAL_NO") = machSerialNo.Text
    newRow("New_date") = machNewDate.Text
    newRow("SPECS") = machSpecs.Text
    newRow("MODEL") = MODEL.Text
    newRow("ASKING_PRI") = ASKING_PRI.Text
    Dim updDS As DataSet = owebservice.InsertInventoryRecord(myDS.GetChanges())

    Public Function InsertInventoryRecord(ByVal custDS As System.Data.DataSet) As System.Data.DataSet
    Dim results() As Object = Me.Invoke("InsertInventoryRecord", New Object() {custDS})
    Return CType(results(0), System.Data.DataSet)
    End Function

    Public Function InsertInventoryRecord(ByVal custDS As DataSet) As DataSet
    Dim custDA As SqlDataAdapter = New SqlDataAdapter
    custDA.InsertCommand = New SqlCommand("INSERT INTO InventoryRecord (STOCK_NO, SERIAL_NO, New_date, SPECS, MODEL, ASKING_PRI) " & _
    "Values(@STOCK_NO, @SERIAL_NO, @New_date, @SPECS, @MODEL, @ASKING_PRI)", myConnection)
    custDA.InsertCommand.Parameters.Add("@STOCK_NO", SqlDbType.NChar, 5, "STOCK_NO")
    custDA.InsertCommand.Parameters.Add("@SERIAL_NO", SqlDbType.NVarChar, 50, "SERIAL_NO")
    custDA.InsertCommand.Parameters.Add("@New_date", SqlDbType.SmallDateTime, 20, "New_date")
    custDA.InsertCommand.Parameters.Add("@SPECS", SqlDbType.NText, 2000, "SPECS")
    custDA.InsertCommand.Parameters.Add("@MODEL", SqlDbType.NChar, 50, "MODEL")
    custDA.InsertCommand.Parameters.Add("@ASKING_PRI", SqlDbType.Float, 15, "ASKING_PRI")
    custDA.UpdateCommand = New SqlCommand("UPDATE Customers Set CustomerID = @CustomerID, " & _
    "CompanyName = @CompanyName WHERE CustomerID = @OldCustomerID", myConnection)
    custDA.UpdateCommand.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID")
    custDA.UpdateCommand.Parameters.Add("@CompanyName", SqlDbType.NChar, 15, "CompanyName")
    Dim myParm As SqlParameter = custDA.UpdateCommand.Parameters.Add("@OldCustomerID", SqlDbType.NChar, 5, "CustomerID")
    myParm.SourceVersion = DataRowVersion.Original
    custDA.DeleteCommand = New SqlCommand("DELETE FROM Customers WHERE CustomerID = @CustomerID", myConnection)
    myParm = custDA.DeleteCommand.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID")
    myParm.SourceVersion = DataRowVersion.Original
    custDA.Update(custDS, "Customers")
    InsertInventoryRecord = custDS
    End Function
    dave, Dec 22, 2003
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page