I am attempting to update a table from data filled into a form.
The variables are pulled from the form like this:
_JEBatchDate = IIf(Me.textJEBatchDate.Text.Trim.Length > 0, Me.textJEBatchDate.Text.Trim, "")
The update sql looks like this...
UPDATE [MAIN] SET [CheckNumber] = @checknumber, [CheckDate] = @checkdate, [CheckCashDate] = @checkcashdate, [CheckAmount] = @checkamount, [PayeeNumber] = @payeenumber, [AccountNumber] = @accountnumber, [Bank] = @bank, [ToTheOrderOf] = @totheorderof, [CheckType] = @checktype, [DatePaperworkSentToPayee] = @datepaperworksenttopayee, [DatePaperworkSentToBank] = @datepaperworksenttobank, [IncompleteReason] = @incompletereason, [RejectReason] = @rejectreason, [CaseNumber] = @casenumber, [BankStatus] = @bankstatus, [CorrWithPayee] = @corrwithpayee, [Comments] = @comments, [BankCredit] = @bankcredit, [Refund] = @refund, [DateFundsRecdFromBank] = @datefundsrecdfrombank, [DateRefundRecd] = @daterefunded, [DateTargetSent] = @datetargetsent, [NumberOfTargets] = @numberoftargets, [DateCreditPostedToCLI] = @datecreditpostedtocli, [DateSentToSGForRepayment] = @datesenttosgforrepayment, [DateClaimWasRepaid] = @dateclaimwasrepaid, [NewCheckNumber] = @newchecknumber, [NewCheckAmount] = @newcheckamount, [ARCHIVED] = @archived, [JEBatchName] = @jebatchname, [JEBatchDate] = @jebatchdate WHERE [ID] = @ID;
All of the values are constructed in this manner:
strValues = strValues & "[JEBatchDate] = @jebatchdate "
Inside a Try...Catch, parameters are constructed this way:
Try
Using updateCmd As New OleDb.OleDbCommand(UpdateSQL, HMOConnection)
updateCmd.Parameters.AddWithValue("@ID", Me.labelID.Text)
updateCmd.Parameters.AddWithValue("@checknumber", _checkNumber)
updateCmd.Parameters.AddWithValue("@checkdate", _checkDate)
I use updateCmd.ExecuteNonQuery() to execute the query.
The code runs through the Try...Catch without error but no update is made to the record. I've double checked all of the names, spellings, connection but still no update is made. Any ideas or suggestions are appreciated!!
EDIT
If I move this line from the top to the bottom I get a data-type mismatch error:
updateCmd.Parameters.AddWithValue("@ID", Me.labelID.Text)
updateCmd.Parameters.AddWithValuelist.Dim rows = updateCmd.ExecuteNonQuery()If rows is non zero, the query does execute and update. If you still cant see the rows, the issue may be: Why saving changes to a database fails? You should also useAddrather thanAddWithValuewhich leaves the Provider to guess what you want. And yes, in OleDB parameters are positional, it doesnt use the name at allupdateCmd.Parameters.AddWithValue("@ID", Me.labelID.Text)fails because yourIDcolumn is probablyintegeron db but you try to set it to a string vialabelID.Text. See @Plutonix comment how to useAddrather.