Solved

vb to c#

Posted on 2009-05-12
3
253 Views
Last Modified: 2013-12-26
I'm trying to create a grid view in c# ..
can someone help me to convert it to C# so I can add it my cs page
here is the code I have in vb

  Public Overrides Sub Retrieve(Optional ByVal dr As DataRow = Nothing)
        Try
            If dr Is Nothing Then
                With MyBase.DataSet.Tables(MyBase.TableName)
                    dr = .Rows(MyBase.RowNumber)
                End With
            End If

            Select Case _intSelectFilter
                Case SelectFilters.All
                    _intVisitID = FieldToString(dr("iVisitID"))
                    _strClientID = FieldToString(dr("sClientID"))
                    _strVisitDate = FieldToDate(dr("dtVisitDate"))
                    '_intVisitTypeID = FieldToString(dr("iVisitTypeID"))
                    _strVisitType = FieldToString(dr("sVisitType"))
                    _intScoreMMSE = FieldToNumber(dr("iMMSE"))
                    _intScoreCornell = FieldToNumber(dr("iCornell"))
                    _intScoreGDS = FieldToNumber(dr("iGDS"))
                    _intScorePHQ9 = FieldToNumber(dr("iPHQ9"))
                    _decScoreGait = FieldToDecimal(dr("dGait"))
                    _intWeight = FieldToNumber(dr("iWeight"))
                    _intTimesHospitalized = FieldToNumber(dr("iTimesHospitalized"))

            End Select

        Catch exp As Exception
            Throw exp

        End Try
    End Sub

#End Region

End Class
0
Comment
Question by:Romacali
[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
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 24369933
I'm assuming FieldToXXXXX() are custom functions you wrote. Also, C# (as of current) does not have a concept of optional parameters. I overloaded the Retrieve function to simulate optional parameters.
public override void Retrieve(DataRow dr)
{
    try
    {
        if (dr == null)
        {
            dr = base.DataSet.Tables(base.TableName).Rows[base.RowNumber];
        }
 
        switch (_intSelectFilter)
        {
            case SelectFilters.All:
                _intVisitID = FieldToString(dr["iVisitID"]);
                _strClientID = FieldToString(dr["sClientID"]);
                _strVisitDate = FieldToDate(dr["dtVisitDate"]);
                //_intVisitTypeID = FieldToString(dr["iVisitTypeID"]);
                _strVisitType = FieldToString(dr["sVisitType"]);
                _intScoreMMSE = FieldToNumber(dr["iMMSE"]);
                _intScoreCornell = FieldToNumber(dr["iCornell"]);
                _intScoreGDS = FieldToNumber(dr["iGDS"]);
                _intScorePHQ9 = FieldToNumber(dr["iPHQ9"]);
                _decScoreGait = FieldToDecimal(dr["dGait"]);
                _intWeight = FieldToNumber(dr["iWeight"]);
                _intTimesHospitalized = FieldToNumber(dr["iTimesHospitalized"]);
                break;
        }
    }
    catch (Exception exp)
    {
        throw exp;
        //throw;   <<-- You may want to consider using "throw" by itself as it preserves the stack trace
    }
}
 
public override void Retrieve()  // Simulate optional parameter
{
    Retrieve(null);
}

Open in new window

0
 
LVL 8

Expert Comment

by:RyanAndres
ID: 24369947
0
 
LVL 32

Assisted Solution

by:Daniel Wilson
Daniel Wilson earned 250 total points
ID: 24370002
try this:

It translates to 2 functions due to the optional parameter.

http://www.builderau.com.au/program/windows/soa/Handling-optional-parameters-in-C-/0,339024644,320268431,00.htm



        public void Retrieve(){
            return Retrieve(null);
        }
 
        public void Retrieve( DataRow dr){
            try{
                if(dr == null){
                    dr = <NameOfMyParentClass>.DataSet.Tables(<NameOfMyParentClass>.TableName).Rows(<NameOfMyParentClass>.RowNumber);
                }
                switch (_intSelectFilter){
                    case SelectFilters.All:
                        _intVisitID = FieldToString(dr["iVisitID"]);
                        //Other rows in here translater similarly
 
                }
            }catch(Exception Exp){
                throw Exp;
            }
        }

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month5 days, 22 hours left to enroll

626 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