Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Moderators
Posted

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.

Visit...Bassic Software
Posted

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?

Posted

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

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...