Retrieving A Bit Column From Sql Database In Vb Net
I have encountered a problem where in my database I have a column that is a bit either 0 or 1 specifying if a user is an admin or is account suspended or not. And in my VB code I a
Solution 1:
Try rdr.GetBoolean(3)
to get Bit values. A bit in SQL Server is the same as a boolean in VB, except it uses 1 and 0 instead of true and false.
Solution 2:
Solution 3:
You want
newrow.Item("SESSuspended") = rdr.GetBoolean(2)
newrow.Item("SESAdmin") = rdr.GetBoolean(3)
You should also change these lines
dtRequests.Columns.Add("SESSuspended", System.Type.GetType("System.Byte"))
dtRequests.Columns.Add("SESAdmin", System.Type.GetType("System.Byte"))
to
dtRequests.Columns.Add("SESSuspended", System.Type.GetType("System.Boolean"))
dtRequests.Columns.Add("SESAdmin", System.Type.GetType("System.Boolean"))
Solution 4:
You can specify the name of the Data Item rather than the index. Such as:
newrow.Item("SESSuspended") = rdr("SESSuspended")
Post a Comment for "Retrieving A Bit Column From Sql Database In Vb Net"