lidds Posted October 5, 2005 Posted October 5, 2005 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 Quote
bri189a Posted October 6, 2005 Posted October 6, 2005 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. 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.