PDA

Click to See Complete Forum and Search --> : C# newbie questions


sinha
Jun 14th, 2005, 01:46 PM
Hi!

I am a newbie on c#.

I have two simple questions:

a) How to print current date and time on my web page. Do I need to include any namespace for it.

b) How to check for null values. I create a dataset. For each item of the rows, I want to perform a nukk checking.

MrPolite
Jun 14th, 2005, 04:07 PM
use DateTime.Now
you can call the .ToShortDateString(), the .ToLongDateString(), or the .ToString() method of that class. ToString would let you customize the way the date is formatted. If you use ToString then you can look up here on MSDN on the formatting strings you can use http://msdn.microsoft.com/library/en-us/cpguide/html/cpconstandarddatetimeformatstrings.asp?frame=true

I dunno about datasets, but in general if (item == null) // do something;

jmcilhinney
Jun 14th, 2005, 06:15 PM
Although I've developed in C# I've only ever actually tried what you're asking in VB. I think the correct C# syntax is:

if (myDataRow["fieldname"].GetType() == typeof(DBNull))

or also:

if (myDataRow["fieldname"] == DBNull.Value)

mar_zim
Jun 14th, 2005, 08:59 PM
or you can do a loop to your dataset

foreach(Datarow dr in mydataset.tables[0].rows){
if(dr[0].tostring=="")<---indicates 1st column
{
//do your job
}
}

jmcilhinney
Jun 14th, 2005, 09:30 PM
or you can do a loop to your dataset

foreach(Datarow dr in mydataset.tables[0].rows){
if(dr[0].tostring=="")<---indicates 1st column
{
//do your job
}
}
What if the field contains an empty string? That's not a null value but will still return true in this case.

mar_zim
Jun 14th, 2005, 09:50 PM
ouchh. sorry im asumming it won't contain empty string. coz usually if i check a null value i used "".

this one will work. if (myDataRow["fieldname"] == DBNull.Value)

sinha
Jun 15th, 2005, 07:17 AM
Thanks a bunch ..........