Reputation: 61
I'm quite new to VB. I'm trying to insert a new record after an input box (Event triggering is Button click). I've got that to work fine, it updates the SQL server.
I then tried to add a loop, with a simple vbYesNo message box, with vbYes triggering the loop. It's not working, it's looping no matter if you click yes or no.
I was hoping it would (On pressing yes), prompt for two barcodes, then it would insert the new record. However I'm getting an error saying "This row already belongs to this table", when I've just added it.
Any help?
Here's the code:
Do While vbYes
TrackCode = InputBox("Please Scan Shipment Barcode")
NewRecord(5) = TrackCode
NewRecord(0) = Ddate
UnqCode = InputBox("Please Scan Parcel Barcode (eg JD123456789)")
NewRecord(6) = UnqCode
DtTable.Rows.Add(NewRecord)
NewRecord.AcceptChanges()
DtTable.AcceptChanges()
TableAdapterManager.UpdateAll(trackingDataSet)
MsgBox("Do You Have Anything Else To Scan?", vbYesNo)
Loop
Sorry if it's something simple. Also all the AcceptChanges()
are due to me trying to figure it out.
Thanks.
Upvotes: 0
Views: 395
Reputation: 39777
Assuming DtTable is a DataTable and NewRecord is a DataRow, try adding the very first line inside of loop:
NewRecord = DtTable.NewRow()
This will create a new data row on every iteration.
Upvotes: 1