filling the form from database

djcybex

Member
Joined
Dec 17, 2002
Messages
10
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
Code:
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 dont attack me cos im still using COM....

Matej
 
Its not that there is no data, its because its casting during this line...
Code:
If Not .Fields(.Fields(i).Name).Value Is DBNull.Value Then
see if you can get the Length > 0 property instead.
 
Oh, I just realized that youre using COM, just use ..

If Not .Fields(.Fields(i).Name).Value = "" Then
 
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?
 
i dont know what this does but it works :)
Code:
If .Fields(.Fields(i).Name).Type <> ADODB.DataTypeEnum.adEmpty Then
  ctrl.Text = .Fields(.Fields(i).Name).Value
End If
 
Back
Top