How do I Evaluate Null value from database?

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 86
Reputation: justapimp is an unknown quantity at this point 
Solved Threads: 1
justapimp justapimp is offline Offline
Junior Poster in Training

How do I Evaluate Null value from database?

 
0
  #1
Mar 13th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 43
Reputation: bbqchickenrobot is an unknown quantity at this point 
Solved Threads: 2
bbqchickenrobot bbqchickenrobot is offline Offline
Light Poster

Re: How do I Evaluate Null value from database?

 
0
  #2
Mar 13th, 2008
you can use nullable types i.e. - int? myVar = ... ;

you can also check to see if the value is = to System.DbNull...
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 86
Reputation: justapimp is an unknown quantity at this point 
Solved Threads: 1
justapimp justapimp is offline Offline
Junior Poster in Training

Re: How do I Evaluate Null value from database?

 
0
  #3
Mar 14th, 2008
How exactly do I do that, I've use IsDBNull, Convert.IsDBNull, IsDBNull.Value and nothing works and I've tried type casting. ????
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 20
Reputation: ravichandra is an unknown quantity at this point 
Solved Threads: 5
ravichandra ravichandra is offline Offline
Newbie Poster

Re: How do I Evaluate Null value from database?

 
0
  #4
Mar 14th, 2008
The following can help you but i am sure whether this is the right way.

While selecting the column check for null values like

select ISNULL(class,-1) from student

If the column class contains null values,the query returns -1 value.
Using this value you can identity the column contains null value.

Good Luck.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: How do I Evaluate Null value from database?

 
0
  #5
Mar 14th, 2008
You need to compare the column value with System.DBNull.Value

So assuming a DataTable for example:

  1. if( myDataTable.Rows[0]["someColumn"].Equals(System.DBNull.Value) )
  2. {
  3. //Handle situation for null value.
  4. }
Last edited by hollystyles; Mar 14th, 2008 at 5:59 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 86
Reputation: justapimp is an unknown quantity at this point 
Solved Threads: 1
justapimp justapimp is offline Offline
Junior Poster in Training

Re: How do I Evaluate Null value from database?

 
0
  #6
Mar 14th, 2008
I tried that method already and it does not work.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: How do I Evaluate Null value from database?

 
0
  #7
Mar 14th, 2008
Hmm... well it works for me. You'll have to post some code or give more information.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 291
Reputation: ericstenson is an unknown quantity at this point 
Solved Threads: 29
Team Colleague
ericstenson's Avatar
ericstenson ericstenson is offline Offline
Posting Whiz in Training

Re: How do I Evaluate Null value from database?

 
0
  #8
Mar 14th, 2008
you can also get the value of the cell and use .text.tostring
then test the length of the string len(abc) > 0
--
"Dummy."
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 86
Reputation: justapimp is an unknown quantity at this point 
Solved Threads: 1
justapimp justapimp is offline Offline
Junior Poster in Training

Re: How do I Evaluate Null value from database?

 
0
  #9
Mar 14th, 2008
Here is the code

  1. [WebMethod]
  2. public int TestDBNullValue(string PID)
  3. {
  4. int ErrorValue = 0;
  5. if (PID.Equals(String.Empty))
  6. {
  7. ErrorValue = 10110; //PID is null or empty
  8. }
  9. else
  10. {
  11. DeviceTableAdapter DeviceAdapter = new DeviceTableAdapter();
  12. JeanPierre.DeviceDataTable DeviceTable = DeviceAdapter.GetDeviceUIDByPID(PID);
  13.  
  14. if (DeviceTable.Count.Equals(0))
  15. {
  16. ErrorValue = 1111; //No device found
  17. }
  18. else
  19. {
  20. JeanPierre.DeviceRow DevRows = DeviceTable[0];
  21.  
  22. if(DevRows.TrackingMode.Equals(System.DBNull.Value))
  23. {
  24. ErrorValue = 1;
  25. }
  26. else
  27. {
  28. ErrorValue = 41;
  29. }
  30. }
  31. }
  32. return (ErrorValue);
  33. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 291
Reputation: ericstenson is an unknown quantity at this point 
Solved Threads: 29
Team Colleague
ericstenson's Avatar
ericstenson ericstenson is offline Offline
Posting Whiz in Training

Re: How do I Evaluate Null value from database?

 
0
  #10
Mar 14th, 2008
i converted from vb.net to c#, so it might not be accurate...

{
if (Strings.len(PID) == 0) {
}
}
--
"Dummy."
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC