KaiserSose
asked on
Check for datareader null value
I have a datareader that fills certain fields:
txtFirstName.Text = dataReader.GetString(8);
txtLastName.Text = dataReader.GetString(9);
txtCompany.Text = dataReader.GetString(10);
Every user has a first and last name, but not all of them have a company. It blows up with a null value, so how do I check for null and skip that line?
txtFirstName.Text = dataReader.GetString(8);
txtLastName.Text = dataReader.GetString(9);
if(datareader.SOMETHING != null)txtCompany.Text = dataReader.GetString(10);
thanks
dave
txtFirstName.Text = dataReader.GetString(8);
txtLastName.Text = dataReader.GetString(9);
txtCompany.Text = dataReader.GetString(10);
Every user has a first and last name, but not all of them have a company. It blows up with a null value, so how do I check for null and skip that line?
txtFirstName.Text = dataReader.GetString(8);
txtLastName.Text = dataReader.GetString(9);
if(datareader.SOMETHING != null)txtCompany.Text = dataReader.GetString(10);
thanks
dave
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sometimes that's all we need... a good kick upside the head! my wife makes sure i get that whenever i need it... :-)
String stringvalue = odbcDataReader.IsDBNull(0) ? null : odbcDataReader.GetString(0 );
ASKER
if(dataReader.IsDBNull(10)
but then you kickstarted my brain and reminded me that i can use the ! so now its like this:
if(!dataReader.IsDBNull(10
All three of you had good answers so I'm splitting the points.
dave