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

  • Thread starter Thread starter Sanjay Tibrewal
  • Start date Start date
S

Sanjay Tibrewal

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.
 
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.
 
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top