Solved

Converting VP.NET to C#

Posted on 2009-04-12
4
473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

732 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