S
shapper
Hi,
I am trying to fill a Generic.List(Of MyClass) with a dataset row
values taken from an MSSQL database:
For Each drPost As DataRow In dsPosts.Tables(0).Rows
Dim post As New Post
With post
.AverageRating = Convert.ToDouble(drPost("PostAverageRating"))
.IsPublished = Convert.ToBoolean(drPost("PostIsPublished"))
.NumberOfComments =
Convert.ToInt32(drPost("PostNumberOfComments"))
.PostId = New Guid(Convert.ToString(drPost("PostId")))
.Title = Convert.ToString(drPost("PostTitle"))
.UpdatedDate = Convert.ToDateTime(drPost("PostUpdatedDate"))
End With
posts.Add(post)
Next drPost
Some of the rows might have empty fields.
I am having an error right on the first conversion (AverageRating):
Object cannot be cast from DBNull to other types.
What am I doing wrong?
Thanks,
Miguel
I am trying to fill a Generic.List(Of MyClass) with a dataset row
values taken from an MSSQL database:
For Each drPost As DataRow In dsPosts.Tables(0).Rows
Dim post As New Post
With post
.AverageRating = Convert.ToDouble(drPost("PostAverageRating"))
.IsPublished = Convert.ToBoolean(drPost("PostIsPublished"))
.NumberOfComments =
Convert.ToInt32(drPost("PostNumberOfComments"))
.PostId = New Guid(Convert.ToString(drPost("PostId")))
.Title = Convert.ToString(drPost("PostTitle"))
.UpdatedDate = Convert.ToDateTime(drPost("PostUpdatedDate"))
End With
posts.Add(post)
Next drPost
Some of the rows might have empty fields.
I am having an error right on the first conversion (AverageRating):
Object cannot be cast from DBNull to other types.
What am I doing wrong?
Thanks,
Miguel