VB Insert problem

pete_484

New member
Joined
Feb 6, 2007
Messages
3
Programming Experience
1-3
Hi, I have the following code...

VB.NET:
Sub AddRentalRes(ByVal CopyID As Integer, ByVal DateOut As Date, ByVal DateDue As Date, ByVal MemberID As Integer)
        Dim RentalResRow As DataRow

        FindMember(MemberID)

        RentalResRow = myDS.Tables("LoanRes").NewRow
        RentalResRow("CustomerID") = MemberID
        RentalResRow("CopyID") = CopyID
        RentalResRow("DateOut") = DateOut
        RentalResRow("DateDue") = DateDue

        Try
            myDS.Tables("LoanRes").Rows.Add(RentalResRow)
        Catch e As System.Data.ConstraintException
            MsgBox("Incorrect data entry", vbExclamation, "Polysoft Media")
            Exit Sub
        End Try

        Try
            myAdapter.Update(myDS, "LoanRes")
        Catch e As System.Data.OleDb.OleDbException
            MsgBox("There was an error during entry", vbExclamation, "Polysoft Media")
            Exit Sub
        End Try
    End Sub
This attempts to insert a row into a DB table. However I am getting a unhandled exception of type 'System.InvalidOperationException'. It says that 'Update requires a valid InsertCommand when passed DataRow collection with new rows'

Can anyone please tell me how I can sort this out?

Thanks.
 
The DataAdapter uses an INSERT INTO sql to send new data back to the database. If you look at the contents of the dataadapter.InsertCommand just before you try to run Update(row), I think youll find that it is blank, or invalid

Kinda like trying to drive to the shops if you dont own a car. Get a car (fix the insert command) and give it another go..
 
Back
Top