Cannot convert to Ref parameter from C# to VB.Net

Discussion in 'ASP .Net' started by Sanjay Tibrewal, Aug 4, 2004.

  1. Hello there,

    I have some code in a VB library dll whose signature is as

    // VB private library code
    Public Sub ExecuteNonQuery(ByVal sConn As String, _
    ByRef oCmd As SqlClient.SqlCommand)

    I create another project in C# and include the library locally. I use the
    following code to
    call the function in VB library

    // C# code
    string m_sConn;
    SqlCommand oCmd2 = new SqlCommand();
    m_oDac.ExecuteNonQuery(m_sConn, oCmd2);

    When I compile the above code I get the following error. Why can't an object
    passed in to the function in C# be converted to a ref object in VB.Net dll?

    C:\Office\Test\WebDAVTest\Class1.cs(516): Argument '2': cannot convert from
    'System.Data.SqlClient.SqlCommand' to 'ref System.Data.SqlClient.SqlCommand'

    Thanks for your help.

    Sanjay.
    Sanjay Tibrewal, Aug 4, 2004
    #1
    1. Advertising

  2. Try

    m_oDac.ExecuteNonQuery(m_sConn, ref oCmd2)

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Sanjay Tibrewal" <> wrote in message
    news:...
    > Hello there,
    >
    > I have some code in a VB library dll whose signature is as
    >
    > // VB private library code
    > Public Sub ExecuteNonQuery(ByVal sConn As String, _
    > ByRef oCmd As SqlClient.SqlCommand)
    >
    > I create another project in C# and include the library locally. I use the
    > following code to
    > call the function in VB library
    >
    > // C# code
    > string m_sConn;
    > SqlCommand oCmd2 = new SqlCommand();
    > m_oDac.ExecuteNonQuery(m_sConn, oCmd2);
    >
    > When I compile the above code I get the following error. Why can't an

    object
    > passed in to the function in C# be converted to a ref object in VB.Net

    dll?
    >
    > C:\Office\Test\WebDAVTest\Class1.cs(516): Argument '2': cannot convert

    from
    > 'System.Data.SqlClient.SqlCommand' to 'ref

    System.Data.SqlClient.SqlCommand'
    >
    > Thanks for your help.
    >
    > Sanjay.
    >
    >
    Kevin Spencer, Aug 4, 2004
    #2
    1. Advertising

  3. Sanjay Tibrewal

    Tom Dacon Guest

    You need to supply the 'ref' keyword in the calling code, as well as in the
    called method's signature. So use:

    m_oDac.ExecuteNonQuery(m_sConn, ref oCmd2);

    Tom Dacon
    Dacon Software Consulting

    "Sanjay Tibrewal" <> wrote in message
    news:...
    > Hello there,
    >
    > I have some code in a VB library dll whose signature is as
    >
    > // VB private library code
    > Public Sub ExecuteNonQuery(ByVal sConn As String, _
    > ByRef oCmd As SqlClient.SqlCommand)
    >
    > I create another project in C# and include the library locally. I use the
    > following code to
    > call the function in VB library
    >
    > // C# code
    > string m_sConn;
    > SqlCommand oCmd2 = new SqlCommand();
    > m_oDac.ExecuteNonQuery(m_sConn, oCmd2);
    >
    > When I compile the above code I get the following error. Why can't an

    object
    > passed in to the function in C# be converted to a ref object in VB.Net

    dll?
    >
    > C:\Office\Test\WebDAVTest\Class1.cs(516): Argument '2': cannot convert

    from
    > 'System.Data.SqlClient.SqlCommand' to 'ref

    System.Data.SqlClient.SqlCommand'
    >
    > Thanks for your help.
    >
    > Sanjay.
    >
    >
    Tom Dacon, Aug 4, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    336
  2. Replies:
    22
    Views:
    752
    peter koch
    Apr 30, 2008
  3. Replies:
    6
    Views:
    345
    James Kanze
    Apr 29, 2008
  4. Navindra Umanee

    strong ref from weak ref?

    Navindra Umanee, Feb 12, 2005, in forum: Ruby
    Replies:
    2
    Views:
    143
    Navindra Umanee
    Feb 12, 2005
  5. Juha Nieminen
    Replies:
    13
    Views:
    611
    Edek Pienkowski
    Aug 29, 2012
Loading...

Share This Page