2 Replies - 372 Views - Last Post: 05 November 2012 - 05:52 PM Rate Topic: -----

#1 404notfound  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 01-November 12

When reading from Access database, get an error when a field is blank

Posted 03 November 2012 - 11:10 PM

When reading from an access database, my code is like this:

 Private Sub PaidNavigateRecords()

        If ds.Tables("Paid").Rows(inc).Item(1) <> "" Then
            txtRanch.Text = ds.Tables("Paid").Rows(inc).Item(1)
        Else
            txtRanch.Text = ""
        End If

        If IsDate(ds.Tables("Paid").Rows(inc).Item(2)) = True Then
            txtDate.Text = ds.Tables("Paid").Rows(inc).Item(2)
        Else
            txtDate.Text = ""
        End If

        If ds.Tables("Paid").Rows(inc).Item(3) <> 0 Then
            txtInvoice.Text = ds.Tables("Paid").Rows(inc).Item(3)
        Else
            txtInvoice.Text = ""
        End If

        If ds.Tables("Paid").Rows(inc).Item(4) <> 0 Then
            txtInvoiceTotal.Text = ds.Tables("Paid").Rows(inc).Item(4)
        Else
            txtInvoiceTotal.Text = ""
        End If

        If IsNumeric(ds.Tables("Paid").Rows(inc).Item(5)) = True Then
            txtAmountPaid.Text = ds.Tables("Paid").Rows(inc).Item(5)
        Else
            txtAmountPaid.Text = ""
        End If

        If IsDate(ds.Tables("Paid").Rows(inc).Item(6)) = True Then
            txtDateOfPayment.Text = ds.Tables("Paid").Rows(inc).Item(6)
        Else
            txtDateOfPayment.Text = ""
        End If

        Try
            If ds.Tables("Paid").Rows(inc).Item(7) <> "" Then
                txtCheckNumber.Text = ds.Tables("Paid").Rows(inc).Item(7)
            Else
                txtCheckNumber.Text = ""
            End If
        Catch ex As Exception
            MessageBox.show(ex.ToString)

        End Try



Its the last bit that gets me. The txtCheckNumber.text. I have it set to text in access, due to the fact that he doesn't pay with a check so AR will just write "American express"...sometimes....
When no data is in the database for this one, I get a:

'System.InvalidCastException was unhandled
Message=Operator '<>' is not defined for type 'DBNull' and string "".'

I've tried everything I can think of to make it just leave the textbox blank and not error out, and nada.
Any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: When reading from Access database, get an error when a field is blank

#2 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: When reading from Access database, get an error when a field is blank

Posted 03 November 2012 - 11:58 PM

Try with If Not IsDbNull(ds.Tables("Paid").Rows(inc).Item(7)) Then
Was This Post Helpful? 0
  • +
  • -

#3 404notfound  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 01-November 12

Re: When reading from Access database, get an error when a field is blank

Posted 05 November 2012 - 05:52 PM

That worked great, thanks lucky.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1