Need help capturing {} in a dataTable's DataRow.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm getting the following Errors during run time and I tried capturing it
using the code below but I'm not able to. I'm also showing in Debug the
value is {}. How can I catch this so it won't create Exception error?
Thanks.

Unable to cast object of type 'System.DBNull' to type 'System.String'.

if ((dr["Primary Group"] != null) && (dr["Primary Group"] != ""))
groupName = (string)dr["Primary Group"];

p- dr["Primary Group"] {} object {System.DBNull}
- Static members
Value {} System.DBNull
 
I'm getting the following Errors during run time and I tried capturing it
using the code below but I'm not able to. I'm also showing in Debug the
value is {}. How can I catch this so it won't create Exception error?
Thanks.

Unable to cast object of type 'System.DBNull' to type 'System.String'.

if ((dr["Primary Group"] != null) && (dr["Primary Group"] != ""))
groupName = (string)dr["Primary Group"];

p- dr["Primary Group"] {} object {System.DBNull}
- Static members
Value {} System.DBNull

if ((dr["Primary Group"] != null) needs to be:

if ((dr["Primary Group"] != DBNull.Value)

Lookup DbNull.Value in the documentation.

Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.com
http://www.arltex.com
http://www.tomchilders.com
http://www.n5ge.com
 
Thank you Otis. I tried System.DBNull before but that didn't work because I
didn't use .Value since I add it, it's now working. Thank you for your help.
--
Thanks.


Otis Mukinfus said:
I'm getting the following Errors during run time and I tried capturing it
using the code below but I'm not able to. I'm also showing in Debug the
value is {}. How can I catch this so it won't create Exception error?
Thanks.

Unable to cast object of type 'System.DBNull' to type 'System.String'.

if ((dr["Primary Group"] != null) && (dr["Primary Group"] != ""))
groupName = (string)dr["Primary Group"];

p- dr["Primary Group"] {} object {System.DBNull}
- Static members
Value {} System.DBNull

if ((dr["Primary Group"] != null) needs to be:

if ((dr["Primary Group"] != DBNull.Value)

Lookup DbNull.Value in the documentation.

Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.com
http://www.arltex.com
http://www.tomchilders.com
http://www.n5ge.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top