Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I keep getting this error when I try to display data into text boxes when a user double clicks on a listing in a list box.

---Option Scrict is ON.---

 

Error Below:

---------------------------

An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll

 

Additional information: Cast from type 'DBNull' to type 'String' is not valid.

----------------------------

 

Private Sub lstProducts_DoubleClick(All the .Net Generated stuff)

       Dim I As Integer
       I = lstProducts.SelectedIndex
       With DsProducts1.Products
           txtProductID.Text = CStr(.Rows(I).Item("ProductID"))
           txtName.Text = CStr(.Rows(I).Item("Name"))
           txtDescrip.Text = CStr(.Rows(I).Item("Descrip"))
           cboQty.SelectedText = CStr(.Rows(I).Item("Qty"))
       End With
End Sub

Any Ideas of what is going on? Everything is stored in the table as Text.

Edited by Robby
Posted

Thanks for the quick help.

 

However, that gave me the same error. I think what is causing the problem is that the list box is populated VIA a SQL statement that contains a DISTINCT clause, so not all values from the table of that field are listed.

 

I think i somehow need it to match the String that the table stores. I am not to sure about it though.

Posted

Not sure if this is the same, but I had a problem that gave the same error.

 

I had an access database with text fields, If the field was blank when it saved it put a null in the access database. When I tried to display the record I got your error.

 

What I ended up doing was writing a function that tested the value in the field and if it was null then it returned "" otherwise it return the value.

 

Hope this helps

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...