Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 25, 2008 08:29 PM by jfbomber
Jun 25, 2008 08:04 PM|LINK
I created a class to update, insert, select and delete data with an object data source but I am getting the following error...
Line 402: user.cellPhoneNumber = reader.GetString(10)Line 403: user.bDay = reader.GetString(11)Line 404: user.gender = reader.GetString(12)
Line 405: user.Newsletter = reader.GetBoolean(13)Line 406: Return
Private m_newsletter As Boolean
Public Property Newsletter() As Boolean
Set(ByVal value As Boolean)
Dim user As New Customer()
user.userName = reader.GetString(0)
user.FirstName = reader.GetString(1)
user.LastName = reader.GetString(2)
user.addressLine1 = reader.GetString(3)
user.addressLine2 = reader.GetString(4)
user.country = reader.GetString(5)
user.state = reader.GetString(6)
user.city = reader.GetString(7)
user.postalCode = reader.GetString(8)
user.homePhoneNumber = reader.GetString(9)
user.cellPhoneNumber = reader.GetString(10)
user.bDay = reader.GetString(11)
user.gender = reader.GetString(12)
user.Newsletter = reader.GetBoolean(13)
What am I doing wrong?
Unable to cast object of type
Jun 25, 2008 08:23 PM|LINK
sounds like the data in the reader (returned by the query e.g reader.GetString(12)) is Boolean. I recommend that try using field names when getting data, when it's not that tied to remembering the order of the columns in the data
user.gender = Cstr(reader("gender")) 'assuming the column name in the data source is gender and you want ti to be a string - otherwise using Cbool if it indeed should be boolean
You can still use ordinals, if you want to - getting them on the first iteration with reader.GetOrdinal and then using with reader.GetXXX methods is perfectly possible, and eses things since you don't have to remember the indexes.
Jun 25, 2008 08:25 PM|LINK
may be "gender" is a boolean field..
Try by changing to...
make sure you click "Mark as Answer" for any post which has helped you.
Jun 25, 2008 08:29 PM|LINK