Solved

Converting VP.NET to C#

Posted on 2009-04-12
4
469 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
ID: 24127462
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
ID: 24127885
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
ID: 24128078
Hope this converter also helps you
http://www.developerfusion.com/tools/convert/vb-to-csharp/
 
0
 

Author Closing Comment

by:chezbrgrs
ID: 31569385
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Server Error 11 58
Diagnostics with Net and Net.Sockets 2 29
jQuery - following an example but can I save data server side? 20 50
Release Dynamically Allocated Memory in C# 3 27
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

809 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