I have been looking for a way to evaluate if a column in a database has a null value in it. So far, every method suggested have failed and I would like to know anyone else have successfully evaluate a null value in C# Visual Studio 2005.
justapimp 1 Junior Poster in Training
Recommended Answers
Jump to PostYou need to compare the column value with System.DBNull.Value
So assuming a DataTable for example:
if( myDataTable.Rows[0]["someColumn"].Equals(System.DBNull.Value) ) { //Handle situation for null value. }
Jump to PostHmm... well it works for me. You'll have to post some code or give more information.
Jump to Postyou can also get the value of the cell and use .text.tostring
then test the length of the string len(abc) > 0
Jump to PostAha, you are using a strongly typed DataTable.
You must be handling the DBNull somehow otherwise you would be getting an exception when populating the table.
Have you tried just == null ?
Jump to PostWhy don't you try to check null in SQL query ?
SELECT ISNULL(EmployeeAddress,'') as EmployeeAddress FROM MasterEmployee ORDER BY EmployeeID
in code :
If Rd.Item("EmployeeAddress").toString.Trim() ="" Then End Id
Thanks.
All 17 Replies
bbqchickenrobot -1 Light Poster
justapimp 1 Junior Poster in Training
ravichandra 0 Newbie Poster
hollystyles 113 Veteran Poster
justapimp 1 Junior Poster in Training
hollystyles 113 Veteran Poster
ericstenson 5 Posting Whiz in Training Team Colleague
justapimp 1 Junior Poster in Training
ericstenson 5 Posting Whiz in Training Team Colleague
justapimp 1 Junior Poster in Training
ericstenson 5 Posting Whiz in Training Team Colleague
justapimp 1 Junior Poster in Training
ericstenson 5 Posting Whiz in Training Team Colleague
hollystyles 113 Veteran Poster
justapimp 1 Junior Poster in Training
streamline 0 Newbie Poster
Kusno 0 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.