DBNull Conversion Exception

  • Thread starter Thread starter gwboolean
  • Start date Start date
G

gwboolean

Guest
I have this plug-in routine for an audit trail for a table that contains what some dimwits consider critical data.

All this routine does is dump all the data from specific columns from a specific table into a specific column in the audit table. The routine is called when a table record is loaded to a form for display (showing what the data was at time of access by the user) and the called again when the user saves any changes they might have made to the record data (showing what the data is at the time the user leaves the form.

There are several problems for me associated with this. I really do not fully understand the use of CType(), I have read up on it and all I can do is scratch my head and just do whatever I am able to make work. However, the primary problem is that I am getting the message below and am unable to load the column with the accumulated data from the input table.

I understand the error message telling me that I am trying to convert null data to a string. I also understand that some of the columns that are supplying the data are indeed null (they frequently have no data). Additionally, if all the columns from the table supplying the data contain data then this routine will execute without failing. What I have concluded from all of that is that the way I have this setup is completely wrong and that something about my use of CType() is blowing this routine out of the water.

So can anyone explain to me what is wrong and what is required to make it work? Please speak slowly, I appear to not be easily understanding things today.

Public Sub AuditChangeRequest()
If mnuMain.TblChangeMasterTableAdapter.FillByChangeID(mnuMain._MasterBase_1_1DataSet.tblChangeMaster, glbintChangeID) = Nothing Then
Dim strMessage As String = vbNewLine & "AUDIT FAILED!!!!" & vbNewLine & "Contact System Administrator."
Dim ErrorMessage As New nspMasterBaseOperations.ErrorMessage
MessageBox.Show(String.Format("{0}{1}", ErrorMessage.Error1003(glbstrErrorMessage), strMessage))
glbfrmWindowForm.Close()
glbfrmWindowForm2.Show()
Else
mnuMain.TblAuditTableAdapter.Fill(mnuMain._MasterBase_1_1DataSet.tblAudit)
'Create Change Request record
Dim ChangeRow As _MasterBase_1_1DataSet.tblAuditRow
ChangeRow = mnuMain._MasterBase_1_1DataSet.tblAudit.NewtblAuditRow
ChangeRow.intChangeID = glbintChangeID
ChangeRow.intEmployeeID = glbintEmployeeID
ChangeRow.dteTime = CDate(CStr(DateAndTime.Now))
ChangeRow.chrBaseObject = glbstrObject
ChangeRow.chrChange = CStr("Change Request Changes:") & vbNewLine & CStr(CType(frmChangeRequest.tblChangeMasterBindingSource.Current, DataRowView).Item("chrTitle")) &
" " & CStr(CType(frmChangeRequest.tblChangeMasterBindingSource.Current, DataRowView).Item("chrRevision")) &
vbNewLine & CStr("Change: ") & CStr(CType(frmChangeRequest.tblChangeMasterBindingSource.Current, DataRowView).Item("chrChangeMade")) &
vbNewLine & CStr("Reason: ") & CStr(CType(frmChangeRequest.tblChangeMasterBindingSource.Current, DataRowView).Item("chrChangeReason")) &
vbNewLine & CStr("Result: ") & CStr(CType(frmChangeRequest.tblChangeMasterBindingSource.Current, DataRowView).Item("chrChangeResult"))
mnuMain._MasterBase_1_1DataSet.tblAudit.Rows.Add(ChangeRow)
mnuMain.tblAuditBindingSource.EndEdit()
mnuMain.TblAuditTableAdapter.Update(mnuMain._MasterBase_1_1DataSet)
End If
End Sub

1290576.jpg


gwboolean

Continue reading...
 
Back
Top