A little problem with one column RRS feed

  • Question

  • I am attempting to add a new record to a table and keep getting this error message.

    Line 209 is the Update()


    Quite frankly, I do not understand why this is so.  When I step through the adding of a new row, there is a value going into the mentioned column (chrChangeID) as well as other columns.  There are several columns that are commented out because I have not decided how I want to put into those yet.

    Private Sub SaveNewRecord() Try Dim FileDataRow As DataRow = MasterBaseTable.NewRow() FileDataRow("chrChangeID") = CStr(lblChangeID.Text) FileDataRow("chrArticleID") = CStr(lblArticle.Text) FileDataRow("chrTitle") = CStr(txtTitle.Text) FileDataRow("chrRevision") = CStr(txtRevision.Text) FileDataRow("chrManager") = CStr(mboEmployee.Text) 'FileDataRow("chrManagerID") = CStr(mboEmployee.Text) FileDataRow("chrOwner") = CStr(cboOwner.Text) FileDataRow("chrWhere") = CStr(cboWhere.Text) 'FileDataRow("chrChangeObject") = CStr() FileDataRow("chrArticleObject") = CStr(_strMasterBase) 'FileDataRow("chrMasterBaseObject") = CStr() FileDataRow("chrChangeMade") = CStr(txtChanges.Text) FileDataRow("chrChangeReason") = CStr(txtReason.Text) FileDataRow("chrChangeResult") = CStr(txtResult.Text) FileDataRow("chrFilePath") = CStr(_strFilePath) FileDataRow("dteOpen") = CDate(CStr(txtOpen.Text)) FileDataRow("blnQualify") = CStr(chkQualify.Checked) MasterBaseTable.Rows.Add(FileDataRow) Catch ex As Exception MessageBox.Show("Change Request not saved." + ControlChars.CrLf + ex.Message + ControlChars.CrLf + ex.ToString, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Me.Close() End Try End Sub

    This particular column is the primary key, but I do not see how that could be a problem.  But then there are many things that I do not see.


    Friday, May 17, 2019 3:34 PM


  • I found what was wrong.  I am not sure how I did it, but the problem was not where I thought it was. 

    The problem was located in this Function.  In the FileIDCommand Where chrChangeID had chrMasterBaseID.

            Public Sub IncrementChangeID()
                Dim strChangeID As String = Nothing
                'Increment ID number and assig to global variable
                strChangeID = CStr(_strChangeMasterID)
                Dim intChangeID As Integer = CInt(Mid(strChangeID, 3, 8))
                intChangeID += 1
                strChangeID = "CR" + CStr(intChangeID)
                    'Open Connection and establish Command object
                    Dim FileIDTable As DataTable = New DataTable
                    FileIDCommand = New OleDbCommand("Select chrChangeID From setChangeID", FileIDConn.MasterBaseConnection)
                    FileIDAdapter = New OleDbDataAdapter()
                    FileIDAdapter.SelectCommand = FileIDCommand
                    Dim FileIDBuild As OleDbCommandBuilder = New OleDbCommandBuilder(FileIDAdapter)
                    'Replace ChangeID value in table
                    FileIDBindingSource.DataSource = FileIDTable
                    FileIDTable.Rows(0).Item(0) = CStr(strChangeID)
                Catch ex As Exception
                    MessageBox.Show("Failed to update Change ID." + ControlChars.CrLf + ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    Exit Sub
                End Try
            End Sub


    • Marked as answer by gwboolean Friday, May 17, 2019 6:15 PM
    Friday, May 17, 2019 6:15 PM