473,503 Members | 3,045 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cannot convert from type to type.

Hi,

I have the following procedure below:
I am getting 2 errors on compile:

Argument '2': cannot convert from 'System.Data.SqlClient.SqlDataReader' to
'ref System.Data.SqlClient.SqlDataReader'

Argument '3': cannot convert from 'System.Text.StringBuilder' to 'ref
System.Text.StringBuilder'

the PrintChildrenRecursive is a class in a referenced DLL that was written in
VB.NET.

this function takes a dataset and loops through it creating a javastring
using stringbuilder that creates a parent-child tree of html hyperlinks.

the printchildrecursive function accepts the Dr and Sbuilder ByReference.

private static void PrintFromRoot(SqlDataReader Dr, StringBuilder SBuilder)
{
PrintChildren PCR = new PrintChildren();

SBuilder.Append("[");
PCR.PrintChildrenRecursive(1, Dr, SBuilder, false);

SBuilder.Remove(1,2); //remove comma and bracket from beginning of string

SBuilder.Append("];");
}

I don't understand why conversion is occuring because they are already of
the correct type as already indicated by the error messages.

thanks

Chris
Nov 17 '05 #1
3 3415
Chris,

You are passing parameters by reference. In order to do so, you need to
use the ref keyword, like this:

obj.PrintFromRoot(ref sqlDataReader, ref stringBuilder);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
Hi,

I have the following procedure below:
I am getting 2 errors on compile:

Argument '2': cannot convert from 'System.Data.SqlClient.SqlDataReader' to
'ref System.Data.SqlClient.SqlDataReader'

Argument '3': cannot convert from 'System.Text.StringBuilder' to 'ref
System.Text.StringBuilder'

the PrintChildrenRecursive is a class in a referenced DLL that was written
in
VB.NET.

this function takes a dataset and loops through it creating a javastring
using stringbuilder that creates a parent-child tree of html hyperlinks.

the printchildrecursive function accepts the Dr and Sbuilder ByReference.

private static void PrintFromRoot(SqlDataReader Dr, StringBuilder
SBuilder)
{
PrintChildren PCR = new PrintChildren();

SBuilder.Append("[");
PCR.PrintChildrenRecursive(1, Dr, SBuilder, false);

SBuilder.Remove(1,2); //remove comma and bracket from beginning of string

SBuilder.Append("];");
}

I don't understand why conversion is occuring because they are already of
the correct type as already indicated by the error messages.

thanks

Chris

Nov 17 '05 #2
Nicholas,

thank you so much!

"Nicholas Paldino [.NET/C# MVP]" wrote:
Chris,

You are passing parameters by reference. In order to do so, you need to
use the ref keyword, like this:

obj.PrintFromRoot(ref sqlDataReader, ref stringBuilder);

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
Hi,

I have the following procedure below:
I am getting 2 errors on compile:

Argument '2': cannot convert from 'System.Data.SqlClient.SqlDataReader' to
'ref System.Data.SqlClient.SqlDataReader'

Argument '3': cannot convert from 'System.Text.StringBuilder' to 'ref
System.Text.StringBuilder'

the PrintChildrenRecursive is a class in a referenced DLL that was written
in
VB.NET.

this function takes a dataset and loops through it creating a javastring
using stringbuilder that creates a parent-child tree of html hyperlinks.

the printchildrecursive function accepts the Dr and Sbuilder ByReference.

private static void PrintFromRoot(SqlDataReader Dr, StringBuilder
SBuilder)
{
PrintChildren PCR = new PrintChildren();

SBuilder.Append("[");
PCR.PrintChildrenRecursive(1, Dr, SBuilder, false);

SBuilder.Remove(1,2); //remove comma and bracket from beginning of string

SBuilder.Append("];");
}

I don't understand why conversion is occuring because they are already of
the correct type as already indicated by the error messages.

thanks

Chris


Nov 17 '05 #3
Chris <Ch***@discussions.microsoft.com> wrote:
Nicholas,

thank you so much!


Note, however, that you very rarely really want to pass a StringBuilder
or a SqlDataReader by reference. Seeing code which does is *usually* an
indication of a lack of understanding of reference types and parameter
passing.

See http://www.pobox.com/~skeet/csharp/parameters.html for more
information.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

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

Similar topics

22
27838
by: Christoph Boget | last post by:
I am getting an error (a few among many) for the following lines of code: retval.BrokerName = (( curRow == System.DBNull.Value ) ? SqlString.Null : (string)curRow ); retval.BrokerGroupId = ((...
9
10509
by: Andy Sutorius | last post by:
Hi, I am receiving the error when compiling the project, "cannot implicitly convert type object to string". The error points to this line of code and underlines the dtrRecipient:...
6
14537
by: Tim Cartwright | last post by:
I have a page that has the login control on it, nothing else. This page inherits from a master page, neither page has any code in it. This page works perfectly when running on the WebDev debug web...
2
15721
by: Christophe | last post by:
class A {} class B {} interface MyInterface { void method(A a); void method(B b); }
7
16616
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7067
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.