Hi,
Try this.
txtCPMain.Text = xyz("STR_CUTTING_PERMIT").ToString
txtOArea.Text = xyz("STR_OPERATING_AREA").ToString
Ken
------------------
"amber" <(E-Mail Removed)> wrote in message
news:199DE4BA-A3DA-4220-8262-(E-Mail Removed)...
> Hello,
> I'm new to this, and I'm not sure how to avoid the following error.
> I use the following code to pull data from a SQL database, depending on
the choice selected in a listbox.
>
> Private Sub lBoxCP_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles lBoxCP.SelectedIndexChanged
>
> dim xyz as DataRowView = lBoxCP.SelectedItem
> txtCPMain.Text = xyz("STR_CUTTING_PERMIT")
> txtOArea.Text = xyz("STR_OPERATING_AREA")
>
> and so on...
> this works great as long as there is data in the field, but if it's empty,
I get an error "Cast from 'DBNull' to 'string' is not valid"
>
> How do I have VB.NET just leave it blank?
>
> Thanks,
> Amber
>
|