Tricky VB to C# conversion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • meerkatinfrance@hotmail.com

    Tricky VB to C# conversion

    I am trying to convert some VB that uses Linq into C#
    Is there anyone out there who is kind enough (clever enough) to show
    me how to convert the following Sub loadAddress into C# for me.

    Sub DoIt()
    Dim WWV5 As New WWV5DataContext
    Dim Xorg As Object

    If Roles.IsUserInR ole("Admin") Then
    Xorg = (From o In WWV5.ORGs Where o.OrgID = ID Select o).Single
    Else
    Xorg = (From o In WWV5.ORGScopies Where o.OrgID = ID Select o).Single
    End If
    loadAddress(Xor g)
    End Sub

    Protected Sub loadAddress(ByR ef pOrg As Object)
    txtName.Text = pOrg.OrgName
    txtCharNum.Text = pOrg.CharNum
    txtAdd1.Text = pOrg.Add1
    End Sub
  • Marc Gravell

    #2
    Re: Tricky VB to C# conversion

    Oh; one other thing; data contexts are usually disposable, so I'd
    actually have something like:

    using(var ctx = new WWV5DataContext ()) {
    Org org;
    if(Roles.IsUser InRole("Admin") ) {
    org = ctx.ORGs.Where( o=>o.OrgID == ID).Single();
    } else {
    org = ctx.ORGScopies. Where(o=>o.OrgI D == ID).Single();
    }
    LoadAddress(org );
    }

    Comment

    • meerkatinfrance@hotmail.com

      #3
      Re: Tricky VB to C# conversion

      Hello Marc,

      Me again !
      I forgot to mention that the using statement you suggestion did not
      work. error:Cannot implicitly convert type 'ORGScopy' to 'ORG'

      I hope you have not gone home :-)

      Regards,

      Pete

      Comment

      Working...