else if part of the code

  • Thread starter Thread starter nasirmajor
  • Start date Start date
N

nasirmajor

DEAR ALL, i have a little problem regarding the following code



protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
string chknullnotnull = "";

SqlDataReader chkreader = null;
chkreader = db.GetReader("Select * from tbl_SubCat where
SId='" + DropDownList1.SelectedItem.Value + "'");

if (chkreader.Read())
{

if (chkreader[4].ToString() != null)
{

chknullnotnull = chkreader[4].ToString();
Response.Write(chknullnotnull);

}

else if (chkreader[4].ToString() == null)
{

Response.Write("null value");

}

}


when dropdownlist1's index is changed and

condition ---chkreader[4].ToString() != null--- gets right

then it do process the following line

Response.Write(chknullnotnull);

and prints the string value of chknullnotnull.

=============================================================
but when

condition ---(chkreader[4].ToString() == null)--- gets right

the following line is not processed and is not displayed on the page

Response.Write("null value");

==========================================================


why (else if) is not getting called

Thanks in advance
 
DEAR ALL, i have a little problem regarding the following code
protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
string chknullnotnull = "";

SqlDataReader chkreader = null;
chkreader = db.GetReader("Select * from tbl_SubCat where
SId='" + DropDownList1.SelectedItem.Value + "'");

if (chkreader.Read())
{

if (chkreader[4].ToString() != null)
{

chknullnotnull = chkreader[4].ToString();
Response.Write(chknullnotnull);

}

else if (chkreader[4].ToString() == null)
{

Response.Write("null value");

}

}

when dropdownlist1's index is changed and

condition ---chkreader[4].ToString() != null--- gets right

then it do process the following line

Response.Write(chknullnotnull);

and prints the string value of chknullnotnull.

=============================================================
but when

condition ---(chkreader[4].ToString() == null)--- gets right

the following line is not processed and is not displayed on the page

Response.Write("null value");

==========================================================

why (else if) is not getting called

Thanks in advance

the "else if" condition IS tested, it's just that the "ToString()"
never gives a "null" value. (if you get a DbNull.Value, the ToString
results in an empty string, which is *not* 'null')
You want to test for "chkreader.IsDBNull(4)".

Hans Kesting
 

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