Solved

Converting VP.NET to C#

Posted on 2009-04-12
4
466 Views
Last Modified: 2012-05-06
Hello Experts -

I am converting some VB.NET code to C#.  Can someone please help me with the following block of code?
With _dstMemberData.Tables(MEMBER_DATA_TABLES.MEMBER_ACCOUNT).Rows(0) _

        _dtmLastActivity = IIf(IsDate(.Item("LastLoginDate").ToString().Trim()), _

        .Item("LastLoginDate").ToString().Trim(), DateTime.MinValue)

End With

Open in new window

0
Comment
Question by:chezbrgrs
  • 2
4 Comments
 

Author Comment

by:chezbrgrs
Comment Utility
Quick addition to the question...Does the following equal the same thing as above?

I also added the new IsDate method.

if (IsDate(_dstMemberData.Tables[(int)MEMBER_DATA_TABLES.MEMBER_PROFILE_INFO_DATA].Rows[0]

    ["LastLoginDate"].ToString().Trim()))

        _dtmLastActivityDate = 

            Convert.ToDateTime(_dstMemberData.Tables[(int)MEMBER_DATA_TABLES.MEMBER_PROFILE_INFO_DATA]

                .Rows[0]["LastLoginDate"].ToString().Trim()); 

else

    _dtmLastActivityDate = DateTime.MinValue;
 

// Method equivalent to IsDate in VB.NET

public static bool IsDate(object Expression)

    {

        string strDate = Expression.ToString();

        try

        {

            DateTime dt = DateTime.Parse(strDate);

            if (dt != DateTime.MinValue && dt != DateTime.MaxValue)

                return true;

            return false;

        }

        catch

        {

            return false;

        }

    }

Open in new window

0
 
LVL 18

Accepted Solution

by:
philipjonathan earned 500 total points
Comment Utility
Yes, I believe you got it correctly translated.

Another way to do that:

string s = _dstMemberData.Tables[(int) MEMBER_DATA_TABLES.MEMBER_PROFILE_INFO_DATA].Rows[0]["LastLoginDate"].ToString().Trim()
DateTime _dtmLastActivityDate = DateTime.MinValue;
try
{
  _dtmLastActivityDate = DateTime.Parse(s);
}
catch
{
}
0
 
LVL 11

Expert Comment

by:Vivek Thangaswamy
Comment Utility
Hope this converter also helps you
http://www.developerfusion.com/tools/convert/vb-to-csharp/
 
0
 

Author Closing Comment

by:chezbrgrs
Comment Utility
Thanks for your time.

I had also tried the converter in the comment below but I found it included keywords that were not in C#.  For example, it listed _dstMemberData.Tables[(int)MEMBER_DATA_TABLES.MEMBER_PROFILE_INFO_DATA].Rows[0].Item["LastLoginDate"]...

From what I've found, '.Item' does not exist in the C# context.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now