Converting VB code to C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RP

    #1

    Converting VB code to C#

    I have to convert this VB code to C#.

    [VB Code]
    Dim dvProduct As DataView =
    CType(sqlDS_Hal loween.Select(D ataSourceSelect Arguments.Empty ),DataView)

    [Attempted C# Code]
    DataView dvProduct =
    sqlDS_Halloween .Select(DataSou rceSelectArgume nts.Empty,DataV iew);

    How to convert to CType?

  • Anthony Jones

    #2
    Re: Converting VB code to C#

    "RP" <rpk.general@gm ail.comwrote in message
    news:1193126974 .940353.109820@ i13g2000prf.goo glegroups.com.. .
    I have to convert this VB code to C#.
    >
    [VB Code]
    Dim dvProduct As DataView =
    CType(sqlDS_Hal loween.Select(D ataSourceSelect Arguments.Empty ),DataView)
    >
    [Attempted C# Code]
    DataView dvProduct =
    sqlDS_Halloween .Select(DataSou rceSelectArgume nts.Empty,DataV iew);
    >
    How to convert to CType?
    >
    DataView dvProduct = (DataView)
    sqlDS_Halloween .Select(DataSou rceSelectArgume nts.Empty);

    --
    Anthony Jones - MVP ASP/ASP.NET


    Comment

    • Clive Dixon

      #3
      Re: Converting VB code to C#

      or in addition to Anthony's answer, you can do

      DataView dvProduct =
      sqlDS_Halloween .Select(DataSou rceSelectArgume nts.Empty,DataV iew) as
      DataView;

      This second method differs in that it will return null (=VB Nothing) if the
      object is not of the correct type.

      Doing

      DataView dvProduct =
      (DataView)sqlDS _Halloween.Sele ct(DataSourceSe lectArguments.E mpty,DataView);

      will throw an InvalidCastExce ption if the object returned by Select is not
      of type DataView.

      "RP" <rpk.general@gm ail.comwrote in message
      news:1193126974 .940353.109820@ i13g2000prf.goo glegroups.com.. .
      >I have to convert this VB code to C#.
      >
      [VB Code]
      Dim dvProduct As DataView =
      CType(sqlDS_Hal loween.Select(D ataSourceSelect Arguments.Empty ),DataView)
      >
      [Attempted C# Code]
      DataView dvProduct =
      sqlDS_Halloween .Select(DataSou rceSelectArgume nts.Empty,DataV iew);
      >
      How to convert to CType?
      >

      Comment

      Working...