Results 1 to 7 of 7

Thread: C# newbie questions

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Malaysia
    Posts
    345

    C# newbie questions

    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.
    Thanks.

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: C# newbie questions

    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...asp?frame=true

    I dunno about datasets, but in general if (item == null) // do something;
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: C# newbie questions

    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)

  4. #4
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: C# newbie questions

    or you can do a loop to your dataset
    Code:
    foreach(Datarow dr in mydataset.tables[0].rows){
       if(dr[0].tostring=="")<---indicates 1st column
    {
    //do your job
    }
    }

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: C# newbie questions

    Quote Originally Posted by mar_zim
    or you can do a loop to your dataset
    Code:
    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.

  6. #6
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416

    Re: C# newbie questions

    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)

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Malaysia
    Posts
    345

    Re: C# newbie questions

    Thanks a bunch ..........
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width