![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Aug 2005
Location: null
Posts: 40
Rep Power: 0
![]() |
How to retrieve nullable data from a MS SQL server database by using a DataReader
Hey guys,
I have a question about selecting data from a MS Sql server database by using a SqlDataReader. The problem is that some of the columns in my table can be null. I want to retrieve a bool value or a null depending on what is in the column. I tried using the bool? type like this: bool? b = (bool?)reader["ConfirmColumn"]; it compiles, but throws an Invalid Cast exception at runtime if the value in the "ConfirmColumn" is NULL. Has any of you had the same problem to solve? Any ideas? Thanks in advance. |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2
![]() |
What is spam? And what is edit?
__________________
You never test the depth of a river with both feet. The believer is happy. The doubter is wise. Free speech carries with it some freedom to listen. The next generation will always surpass the previous one. It`s one of the never ending cycles of life. |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
Hi,
I believe this is what you need csharp Syntax (Toggle Plain Text)
I am better with VB .NET so i tried converting it over to C#, one thing to watch out for, I wasn't sure whether or not to use "is" or "==", in VB .NET you use "is" when working with potential null conditionals, wasn't sure if C# was the same or not. so you may need to change it if it doesn't work. try this first though. good luck
__________________
I have never let my schooling interfere with my education. -Mark Twain- Xbox live gamertag: melbolt |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Aug 2005
Location: null
Posts: 40
Rep Power: 0
![]() |
thank you melbolt - it is a good idea
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how do i automate text data and input into database? | lionel84 | C# | 0 | Jun 26th, 2005 9:35 PM |
| Help in QBASIC (I think it's similar to VB) | phoenix987 | Visual Basic | 3 | May 9th, 2005 12:33 PM |
| Help with a QBASIC program | phoenix987 | Other Programming Languages | 4 | May 5th, 2005 12:27 PM |