Access Databases
-
Hi, I'm writing a Windows application that's a front end interface for an Access database. I'm using VB.NET and I'm getting a very strange error when I try to edit a record in one of my tables. The error says: "5 - Cannot set 'Discrepancy'" Discrepancy is the column name. The strange thing is that the line of code that's raising the error is within a Try, Catch, End Try block but the error is raised without the code execution passing through the Catch part of the block! And even stranger than that, the new value that I'm setting to the 'Discrepancy' field is being set, even though the error message says that it can't set it!! I've checked, double-checked, and triple-checked all of the usual suspects (spelling, table mapping, schema, oleadapter configuration, etc) and everything seems fine. I can't for the life of me see what is wrong. Can anyone help please? I've included my code below. The line that's generating the error is the one with the EndEdit() method. I've also tried checking for errors on the line immediately before the EndEdit() method and there were none. Try Dim Record As DataRow = Me.dtsRent.Tables(0).Rows(Me.cmbWeek.SelectedIndex) Dim Balanced as String If CInt(Me.txtRentDisc.Text) = 0 Then Balanced = "Yes" Else Balanced = "No" Record.BeginEdit() Record.Item("Modified By") = Profile("Officer").ToString Record.Item("Date Modified") = DateTime.Now.ToString Record.Item("Reconciled") = Balanced Record.Item("Total Payments") = CDec(Me.txtRentPayments.Text) Record.Item("HBP19 Controls") = CDec(Me.txtRentHB19.Text) Record.Item("Discrepancy") = CDec(Me.txtRentDisc.Text) Record.EndEdit() Me.adpRent.Update(Me.dtsRent) Catch ex As Exception MsgBox(Err.Number & " - " & Err.Description) End Try Thanks in advance. QC
-
Hi, I'm writing a Windows application that's a front end interface for an Access database. I'm using VB.NET and I'm getting a very strange error when I try to edit a record in one of my tables. The error says: "5 - Cannot set 'Discrepancy'" Discrepancy is the column name. The strange thing is that the line of code that's raising the error is within a Try, Catch, End Try block but the error is raised without the code execution passing through the Catch part of the block! And even stranger than that, the new value that I'm setting to the 'Discrepancy' field is being set, even though the error message says that it can't set it!! I've checked, double-checked, and triple-checked all of the usual suspects (spelling, table mapping, schema, oleadapter configuration, etc) and everything seems fine. I can't for the life of me see what is wrong. Can anyone help please? I've included my code below. The line that's generating the error is the one with the EndEdit() method. I've also tried checking for errors on the line immediately before the EndEdit() method and there were none. Try Dim Record As DataRow = Me.dtsRent.Tables(0).Rows(Me.cmbWeek.SelectedIndex) Dim Balanced as String If CInt(Me.txtRentDisc.Text) = 0 Then Balanced = "Yes" Else Balanced = "No" Record.BeginEdit() Record.Item("Modified By") = Profile("Officer").ToString Record.Item("Date Modified") = DateTime.Now.ToString Record.Item("Reconciled") = Balanced Record.Item("Total Payments") = CDec(Me.txtRentPayments.Text) Record.Item("HBP19 Controls") = CDec(Me.txtRentHB19.Text) Record.Item("Discrepancy") = CDec(Me.txtRentDisc.Text) Record.EndEdit() Me.adpRent.Update(Me.dtsRent) Catch ex As Exception MsgBox(Err.Number & " - " & Err.Description) End Try Thanks in advance. QC
Try surrounding the field name with square brackets - "[Discrepancy]". Access has some weird keywords... We need to graduate from the ridiculous notion that greed is some kind of elixir for capitalism - it's the downfall of capitalism. Self-interest, maybe, but self-interest run amok does not serve anyone. The core value of conscious capitalism is enlightened self-interest. Patricia Aburdene Bulls make money, bears make money, pigs get slaughtered. Jim Cramer
-
Try surrounding the field name with square brackets - "[Discrepancy]". Access has some weird keywords... We need to graduate from the ridiculous notion that greed is some kind of elixir for capitalism - it's the downfall of capitalism. Self-interest, maybe, but self-interest run amok does not serve anyone. The core value of conscious capitalism is enlightened self-interest. Patricia Aburdene Bulls make money, bears make money, pigs get slaughtered. Jim Cramer
Thanks Rob, However, the field/column name is a string data type in VB. Including the square brackets in the string would make them part of the field/column name, rendering it unrecognisable (if that's a real word). Square brackets can only be used in an SQL command. QC -- modified at 11:59 Friday 28th April, 2006