trippbrown Posted November 14, 2003 Posted November 14, 2003 (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 November 14, 2003 by Robby Quote
Moderators Robby Posted November 14, 2003 Moderators Posted November 14, 2003 get rid of Cstr() and use Ctype() Ctype(.Rows(I).Item("ProductID"), string) Quote Visit...Bassic Software
trippbrown Posted November 14, 2003 Author Posted November 14, 2003 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. Quote
trippbrown Posted November 17, 2003 Author Posted November 17, 2003 Any one got some ideas? Anyone? Quote
pendragon Posted November 17, 2003 Posted November 17, 2003 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 Quote
trippbrown Posted November 17, 2003 Author Posted November 17, 2003 thanks Thanks for the help, however it was nothing of that nature. My dumbass self never noticed that somehow my Fill method was commented out. Dam comments. :) thanks.:) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.