473,378 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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.
Nov 18 '05 #1
2 3653
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" <st**************@wsgr.com> wrote in message
news:uJ**************@TK2MSFTNGP12.phx.gbl...
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.

Nov 18 '05 #2
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" <st**************@wsgr.com> wrote in message
news:uJ**************@TK2MSFTNGP12.phx.gbl...
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.

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Sydex | last post by:
When I compile code I get error C2664: 'Integration::qgaus' : cannot convert parameter 1 from 'double (double)' to 'double (__cdecl *)(double)' in this part : double Integration::quad2d(double...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
6
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void...
4
by: kishor | last post by:
I have an activeX dll, I am calling one function from that dll. I am using C# as coding language. I am getting following error. cannot convert from 'string' to 'ref string' How do I call this...
1
by: Gary | last post by:
I have a strange compile error. C2664 cannot convert parameter 2 from int to int... Earlier in my code I was setting up my dataset... I add an int field like so... ...
9
by: Igor Okulist | last post by:
int func(void**); { short* p = NULL; func(&p); //<<< here } Could somebody remind me why is this not allowed ? error message: "cannot convert parameter from 'short **' to 'void **'"
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
1
by: td0g03 | last post by:
I have no idea why am I getting an error C2664: 'parseInput' : cannot convert parameter 2 from 'main::WORD_STRUCT ' to 'struct WORD_STRUCT ' #include <stdio.h> #include <stdlib.h> #include...
7
by: mng2nf | last post by:
i'm having problems with this portion of code... the entire program is an invoice for a carpet installation asking for the room dimensions and various rates and amounts to calculate how much to...
5
by: slizorn | last post by:
well the error i get is the title above: error C2664: 'searchTree' : cannot convert parameter 2 from 'const char *' to 'char' error is form this line searchTree(treeObj->root ,data1.c_str());...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.