Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi ya guys,

 

Can't seem to figure this one out, would not mind some help from the experts :p

 

               Do While myReader.Read
                   If (myReader.Item("Disp")) <> "Admin" Then
                       Dim dateCol = New DateTimeColumn(myReader.Item("Disp"))
                       dateCol.EditorStyle = EditorStyle.DropDown
                       dateCol.FormatString = "dd/MM/yyyy"
                       Me.lstDates.Columns.Items.AddRange(New Column() {dateCol})

                       For j = 0 To dsDates.Tables("dates").Rows.Count - 1                            
                           If Trim(dsDates.Tables("dates").Rows(j).Item((myReader.Item("Disp")) & "To")) Is DBNull.Value Then
                               strDateTo = Nothing
                           Else
                               strDateTo = Trim(dsDates.Tables("dates").Rows(j).Item((myReader.Item("Disp")) & "To"))
                           End If
                           If Trim(dsDates.Tables("dates").Rows(j).Item((myReader.Item("Disp")) & "From")) Is DBNull.Value Then
                               strDateFrom = Nothing
                           Else
                               strDateFrom = Trim(dsDates.Tables("dates").Rows(j).Item((myReader.Item("Disp")) & "From"))
                           End If
                       Next
                   End If
               Loop

 

It's giving me an error of "Cast from type 'DBNull' to type 'String' is not valid." on the following line.

 

If Trim(dsDates.Tables("dates").Rows(j).Item((myReader.Item("Disp")) & "To")) Is DBNull.Value Then

 

I am using a third party of software incase some of the code look strange.

 

Thanks inadvance

 

Simon

Posted

Change this:

 

If Trim(dsDates.Tables("dates").Rows(j).Item((myReader.Item("Disp")) & "To")) Is DBNull.Value Then

 

To:

Dim myVal as Object = dsDatas.Tables("dates").Rows(j).Item((myReader.Item("Disp)) & "To))

If Not myVal Is DBNull.Value Then

'Your code here

End If

 

You can't trim a DBNull value.

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