I have an application where I am filling text boxes with data from a table. Every now and then, not all the fields in the table are going to contain data. For instance some records will have notes and others won't. Right now if I try and do this (below) I get Cast from type DBNull to type String is not valid
VB Code:
  1. Try
  2.                 cnn.Open()
  3.                 dr = cmd.ExecuteReader
  4.                 While dr.Read()
  5.                     tbRoNumb.Text = dr("RoNumber")
  6.                     tbLastName.Text = dr("LastName")
  7.                     tbFirstName.Text = dr("FirstName")
  8.                     tbVehicle.Text = dr("Vehicle")
  9.                     tbInsurer.Text = dr("Insurer")
  10.                     tbColorCode.Text = dr("ColorCode")
  11.                     tbAmount.Text = dr("Amount")
  12.                     tbDateEntered.Text = dr("DateEntered")
  13.                     tbDeliverDate.Text = dr("DeliveryDate")
  14.                     tbDeliverTime.Text = dr("DeliveryTime")
  15.                     tbPartsDate.Text = dr("PartsDate")
  16.                     tbF.Text = dr("Frame")
  17.                     tbM.Text = dr("Mech")
  18.                     tbA.Text = dr("Align")
  19.                     tbB.Text = dr("Body")
  20.                     tbP.Text = dr("Paint")
  21.                     tbReleaseDay.Text = dr("ReleaseDate")
  22.                     tbReleaseTime.Text = dr("ReleaseTime")
  23.                     CB1.Checked = dr("CB1")
  24.                     CB2.Checked = dr("CB2")
  25.                     CB3.Checked = dr("CB3")
  26.                     CB4.Checked = dr("CB4")
  27.                     CB5.Checked = dr("CB5")
  28.                     tbMemo.Text = dr("Notes")
  29.                 End While
  30.                 cnn.Close()
How do I do this and still allow for nulls in one or more fields?