djcybex Posted December 17, 2002 Posted December 17, 2002 hey all! i try to fill the form from mysql database. I connect to DB successfuly. my form has a lot of text and combo boxes. i named all the same as table fields so i could use this kind of trick to fill them For i = 0 To rs.Fields.Count - 1 With rs For Each ctrl In Controls If TypeOf ctrl Is TextBox Then If ctrl.Name = .Fields(i).Name Then If Not .Fields(.Fields(i).Name).Value Is DBNull.Value Then ctrl.Text = .Fields(.Fields(i).Name).Value End If End If End If Next End With Next here is my problem.... it fills some data successfuly (Date, Name, Age, ... ) but then when it tries to fill data with type set to TEXT (Description) i get error: Cast from type 'DBNull' to type 'String' is not valid. funny thing is that this field (Description) in database contains data.... it is not empty or null please help if you can! thanx in advance p.s. please don't attack me cos i'm still using COM.... Matej Quote
Moderators Robby Posted December 18, 2002 Moderators Posted December 18, 2002 It's not that there is no data, it's because it's casting during this line... If Not .Fields(.Fields(i).Name).Value Is DBNull.Value Then see if you can get the Length > 0 property instead. Quote Visit...Bassic Software
Moderators Robby Posted December 18, 2002 Moderators Posted December 18, 2002 Oh, I just realized that you're using COM, just use .. If Not .Fields(.Fields(i).Name).Value = "" Then Quote Visit...Bassic Software
djcybex Posted December 18, 2002 Author Posted December 18, 2002 if i try to use <> "" then i get new error for first data i get from database: Cast from string "" to type 'Date' is not valid. first record has all fields full of data..... and still get problems is it posible to check what type is the field? Quote
djcybex Posted December 18, 2002 Author Posted December 18, 2002 i don't know what this does but it works :) If .Fields(.Fields(i).Name).Type <> ADODB.DataTypeEnum.adEmpty Then ctrl.Text = .Fields(.Fields(i).Name).Value End If 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.