473,382 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

else if part of the code

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

Jul 14 '06 #1
3 898
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
Jul 14 '06 #2
You want to test for "chkreader.IsDBNull(4)".
dear it still not working

Jul 14 '06 #3
Try IsDBNull(chkreader[4])
--
Harolds
"na********@yahoo.com" wrote:
>
You want to test for "chkreader.IsDBNull(4)".

dear it still not working

Jul 14 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Joe Blow | last post by:
I'm sure I'm missing something blindingly obvious here. I am relatively new to PHP, so excuse dumb mistakes. I a trying to check a form submitted from an earlier page, and check $_POST for empty...
3
by: JD | last post by:
I have the below code that displays a small thumbnail if a user is saluted, if they aren't saluted it checks to see if they might have a profile picture, this all works with the exception that is...
23
by: Invalid User | last post by:
While trying to print a none empty list, I accidentaly put an "else" statement with a "for" instead of "if". Here is what I had: if ( len(mylist)> 0) : for x,y in mylist: print x,y else:...
27
by: Ron Adam | last post by:
There seems to be a fair amount of discussion concerning flow control enhancements lately. with, do and dowhile, case, etc... So here's my flow control suggestion. ;-) It occurred to me (a...
5
by: WindAndWaves | last post by:
Hi Team The function below searches all the tables in a database. However, if subsearch = true then it searches all the objects listed in a recordset (which are all table names). I thought to...
8
by: Jim Michaels | last post by:
C:\prj\quiz\withusers>php tareports.php PHP Parse error: syntax error, unexpected T_ELSE in C:\prj\quiz\withusers\tareports.php on line 205 this is the section of code. if (isset($row4)) {...
22
by: John | last post by:
Hi Folks, I'm experimenting a little with creating a custom CEdit control so that I can decide on what the user is allowed to type into the control. I started off only allowing floating point...
5
by: bigden007 | last post by:
Hi, I have a if..else statement in my script. The statements all execute fine, but the problem is , even if the IF part of the statement is true, the else part executes as well. The verion of...
2
by: aszush | last post by:
//Title: Programming Assignment 1 //Version: //Copyright: Copyright (c) 1999 //Author: Andrew //Company: //Description: Computes employee's weekly gross and net pay....
17
by: JRough | last post by:
I'm trying to get error proof code. I have this code which seems to work but now I look at it I think it should be elseif not else and I wonder why it works. It is in the block:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.