cannot convert from type to type.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

thank you so much!

Nicholas Paldino said:
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]
- (e-mail address removed)

Chris said:
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
 

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