0

Hello Everyone,

In my sql database I am having a country field and a State field with some values and also some null values and I am populating the country values into a dropdown list box in the frontend using database connection

e.g.
Country
India
Indonesia
null
Iran

My requirement is, if I select the particular country in the dropdown list box, I need to display the rspctive state assigned to it, If I select the null value, all the state and country should be displayed. I need the coding for the above null condition in c#.

Thanks
Sasikala

4
Contributors
3
Replies
6
Views
10 Years
Discussion Span
Last Post by zid8ne
1

I'm not certain of what you require. But perhaps you need DBNull.Value this represents a null database value. For example you can comapare a value in a DataSet to DBNull.Value which returns true if the value is null.

if(myDataSet.Rows[0]["columnName"] == DBNull.Value)
         //the value is null.
1

one method is

string.IsNullOrEmpty(stringtoCheck)

another method is

if(stringtoCheck==DBNull.Value)

both works but difference is you can check string.Empty also in the First method to check for DB nulls you have to use second method

0

you can also use ISNULL function in your query since your are getting the data from the database

SELECT
ISNULL(COUNTRY, '') AS COUNTRY
FROM TABLENAME

Edited by zid8ne: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.