By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,682 Members | 1,999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,682 IT Pros & Developers. It's quick & easy.

Pass string to method that calls for object

P: n/a
Hello, all.

First off, I apologize for my ignorance. I am not used to working with non-variants, and it has been a LONG time since
I dealt with OOP.

I need to pass a string to a compiled method that requires an array of objects, like:

execute(string[],object[])

it was obviously created as an object because it was meant to accept input from the page form, but I want to send it
information from a datatable instead. Here's the relevant code:

---------------------

DataTable myTable = ExecuteDataTable("merge","SELECT * FROM merge");

string[] fieldNames = new string[myTable.Rows.Count];
object[] fieldValues = new string[myTable.Rows.Count];

for (int i = 0; i < myTable.Rows.Count; i++)
{
DataRow row = myTable.Rows[ i ];
// DataColumn col = myTable.Columns[];
fieldNames[i] = row["Fieldname"];
fieldValues[i] = row["FieldValue"]; //This is what needs to be an object instead of a string
}
--------------------
Here, of course, the compiler throws fits:

-------------------

Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

shan.aspx.cs(133,31): error CS0029: Cannot implicitly convert type 'object' to 'string'

---------------------

I vaguely remember creating objects from javascript, but only as a long shdowed dream. I really would appreciate any
help you might give in getting this to work, either by helping me convert the FieldValue to an object or any other
workaround.

Thanks again.

Shannon
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Build the program again in Visual Studio, ad when you see the error message,
double-click it. Just prior to the highlighted code, insert the following:

(string)

This will implicitly cast it to the string you require, or I'm a Dutchman's
uncle!

HTH,

Arnie Van Huiesen

"mrgr8avill" wrote:
Hello, all.

First off, I apologize for my ignorance. I am not used to working with non-variants, and it has been a LONG time since
I dealt with OOP.

I need to pass a string to a compiled method that requires an array of objects, like:

execute(string[],object[])

it was obviously created as an object because it was meant to accept input from the page form, but I want to send it
information from a datatable instead. Here's the relevant code:

---------------------

DataTable myTable = ExecuteDataTable("merge","SELECT * FROM merge");

string[] fieldNames = new string[myTable.Rows.Count];
object[] fieldValues = new string[myTable.Rows.Count];

for (int i = 0; i < myTable.Rows.Count; i++)
{
DataRow row = myTable.Rows[ i ];
// DataColumn col = myTable.Columns[];
fieldNames[i] = row["Fieldname"];
fieldValues[i] = row["FieldValue"]; //This is what needs to be an object instead of a string
}
--------------------
Here, of course, the compiler throws fits:

-------------------

Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

shan.aspx.cs(133,31): error CS0029: Cannot implicitly convert type 'object' to 'string'

---------------------

I vaguely remember creating objects from javascript, but only as a long shdowed dream. I really would appreciate any
help you might give in getting this to work, either by helping me convert the FieldValue to an object or any other
workaround.

Thanks again.

Shannon

Nov 16 '05 #2

P: n/a
Thanks, Arnie, but two problems:

1) I don't have VS.NET (got out of the gig way back in VS6, and can't afford it just to keep my own stuff going), and

2) the class the method belong to is in third party compiled code - no access to the source.

So I will not be able to determine your family heritage for you :) But anything else you have would be highly
appreciated.

Thanks again

Shannon

On Fri, 1 Oct 2004 19:19:02 -0700, "cashdeskmac" <ca*********@discussions.microsoft.com> wrote:
Build the program again in Visual Studio, ad when you see the error message,
double-click it. Just prior to the highlighted code, insert the following:

(string)

This will implicitly cast it to the string you require, or I'm a Dutchman's
uncle!

HTH,

Arnie Van Huiesen

"mrgr8avill" wrote:
Hello, all.

First off, I apologize for my ignorance. I am not used to working with non-variants, and it has been a LONG time since
I dealt with OOP.

I need to pass a string to a compiled method that requires an array of objects, like:

execute(string[],object[])

it was obviously created as an object because it was meant to accept input from the page form, but I want to send it
information from a datatable instead. Here's the relevant code:

---------------------

DataTable myTable = ExecuteDataTable("merge","SELECT * FROM merge");

string[] fieldNames = new string[myTable.Rows.Count];
object[] fieldValues = new string[myTable.Rows.Count];

for (int i = 0; i < myTable.Rows.Count; i++)
{
DataRow row = myTable.Rows[ i ];
// DataColumn col = myTable.Columns[];
fieldNames[i] = row["Fieldname"];
fieldValues[i] = row["FieldValue"]; //This is what needs to be an object instead of a string
}
--------------------
Here, of course, the compiler throws fits:

-------------------

Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

shan.aspx.cs(133,31): error CS0029: Cannot implicitly convert type 'object' to 'string'

---------------------

I vaguely remember creating objects from javascript, but only as a long shdowed dream. I really would appreciate any
help you might give in getting this to work, either by helping me convert the FieldValue to an object or any other
workaround.

Thanks again.

Shannon

Nov 16 '05 #3

P: n/a
mrgr8avill wrote:
I need to pass a string to a compiled method that requires an array of objects, like:

execute(string[],object[])

it was obviously created as an object because it was meant to accept input from the page form, but I want to send it
information from a datatable instead. Here's the relevant code:

DataTable myTable = ExecuteDataTable("merge","SELECT * FROM merge");

string[] fieldNames = new string[myTable.Rows.Count];
object[] fieldValues = new string[myTable.Rows.Count];

for (int i = 0; i < myTable.Rows.Count; i++)
{
DataRow row = myTable.Rows[ i ];
// DataColumn col = myTable.Columns[];
fieldNames[i] = row["Fieldname"];
fieldValues[i] = row["FieldValue"]; //This is what needs to be an object instead of a string
}

Here, of course, the compiler throws fits:
-------------------
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

shan.aspx.cs(133,31): error CS0029: Cannot implicitly convert type 'object' to 'string'
---------------------


The line that is giving the error is:

fieldNames[i] = row["Fieldname"];

This is because when you access a column on a row that way the returned
type is object and you are trying to insert that object into an array of
string. You want to convert to string first. Options include casting
as Arnie stated. You can also use Convert.ToString(row["Fieldname"]).
--
Tom Porterfield
Nov 16 '05 #4

P: n/a
Geeze -- see, I TOLD you I was ignorant. Good LORD!!!!!!!

Thank you very much for your help -- I am going to go soak my head in the toilet...

No WONDER it said object to string instead of string to object.

Glad I get mail every day, or I'd probably forget my own name.

Thanks again, Tom, I really appreciate it.

Shannon
On Fri, 01 Oct 2004 22:51:15 -0400, Tom Porterfield <tp******@mvps.org> wrote:
mrgr8avill wrote:
I need to pass a string to a compiled method that requires an array of objects, like:

execute(string[],object[])

it was obviously created as an object because it was meant to accept input from the page form, but I want to send it
information from a datatable instead. Here's the relevant code:

DataTable myTable = ExecuteDataTable("merge","SELECT * FROM merge");

string[] fieldNames = new string[myTable.Rows.Count];
object[] fieldValues = new string[myTable.Rows.Count];

for (int i = 0; i < myTable.Rows.Count; i++)
{
DataRow row = myTable.Rows[ i ];
// DataColumn col = myTable.Columns[];
fieldNames[i] = row["Fieldname"];
fieldValues[i] = row["FieldValue"]; //This is what needs to be an object instead of a string
}

Here, of course, the compiler throws fits:
-------------------
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.

shan.aspx.cs(133,31): error CS0029: Cannot implicitly convert type 'object' to 'string'
---------------------


The line that is giving the error is:

fieldNames[i] = row["Fieldname"];

This is because when you access a column on a row that way the returned
type is object and you are trying to insert that object into an array of
string. You want to convert to string first. Options include casting
as Arnie stated. You can also use Convert.ToString(row["Fieldname"]).

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.