468,283 Members | 2,005 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,283 developers. It's quick & easy.

Convert int to String Error

This worked in the command window while in debug mode

?table.Rows[0].ItemArray["ColumnName"].ToString()
"f0165f94-648f-4997-b578-11d89c8b1f61"

But gives the error below when I compile.

Cannot implicitly convert type 'string' to 'int' and the word ColumnName is
underlined.

Here is a code snippett (with error line marked with an asterisk):

DataSet ds = new DataSet();
ds.ReadXml(@"D:\Data\test.xml", XmlReadMode.ReadSchema);

foreach (DataTable table in ds.Tables)
{

for (int index = 0; index <= table.Rows.Count; index++)
{

{
SqlCommand command = new SqlCommand("ImportData", conn);
command.CommandType = CommandType.StoredProcedure;
adapter.InsertCommand = command;

SqlParameter param;

param = command.Parameters.Add("@columnID", SqlDbType.UniqueIdentifier);
* param.Value = new
Guid(table.Rows[index].ItemArray["ColumnName"].ToString());
}
}
}

Did I do something wrong that I am not seeing, or is there another way to
reference a column?
Sep 5 '06 #1
4 1771
Hi,

Just use

table.Rows[0]["ColumnName"].ToString()
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Mike Collins" <Mi*********@discussions.microsoft.comwrote in message
news:25**********************************@microsof t.com...
This worked in the command window while in debug mode

?table.Rows[0].ItemArray["ColumnName"].ToString()
"f0165f94-648f-4997-b578-11d89c8b1f61"

But gives the error below when I compile.

Cannot implicitly convert type 'string' to 'int' and the word ColumnName
is
underlined.

Here is a code snippett (with error line marked with an asterisk):

DataSet ds = new DataSet();
ds.ReadXml(@"D:\Data\test.xml", XmlReadMode.ReadSchema);

foreach (DataTable table in ds.Tables)
{

for (int index = 0; index <= table.Rows.Count; index++)
{

{
SqlCommand command = new SqlCommand("ImportData", conn);
command.CommandType = CommandType.StoredProcedure;
adapter.InsertCommand = command;

SqlParameter param;

param = command.Parameters.Add("@columnID",
SqlDbType.UniqueIdentifier);
* param.Value = new
Guid(table.Rows[index].ItemArray["ColumnName"].ToString());
}
}
}

Did I do something wrong that I am not seeing, or is there another way to
reference a column?

Sep 5 '06 #2
Mike,

This should not have worked in the command window.

The reason it fails when you compile is because the ItemArray property
returns an array of values representing the row. Arrays are indexed on
integers, not strings, which is why you can't compile it.

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

"Mike Collins" <Mi*********@discussions.microsoft.comwrote in message
news:25**********************************@microsof t.com...
This worked in the command window while in debug mode

?table.Rows[0].ItemArray["ColumnName"].ToString()
"f0165f94-648f-4997-b578-11d89c8b1f61"

But gives the error below when I compile.

Cannot implicitly convert type 'string' to 'int' and the word ColumnName
is
underlined.

Here is a code snippett (with error line marked with an asterisk):

DataSet ds = new DataSet();
ds.ReadXml(@"D:\Data\test.xml", XmlReadMode.ReadSchema);

foreach (DataTable table in ds.Tables)
{

for (int index = 0; index <= table.Rows.Count; index++)
{

{
SqlCommand command = new SqlCommand("ImportData", conn);
command.CommandType = CommandType.StoredProcedure;
adapter.InsertCommand = command;

SqlParameter param;

param = command.Parameters.Add("@columnID",
SqlDbType.UniqueIdentifier);
* param.Value = new
Guid(table.Rows[index].ItemArray["ColumnName"].ToString());
}
}
}

Did I do something wrong that I am not seeing, or is there another way to
reference a column?

Sep 5 '06 #3
That syntax works...thanks.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

Just use

table.Rows[0]["ColumnName"].ToString()
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Mike Collins" <Mi*********@discussions.microsoft.comwrote in message
news:25**********************************@microsof t.com...
This worked in the command window while in debug mode

?table.Rows[0].ItemArray["ColumnName"].ToString()
"f0165f94-648f-4997-b578-11d89c8b1f61"

But gives the error below when I compile.

Cannot implicitly convert type 'string' to 'int' and the word ColumnName
is
underlined.

Here is a code snippett (with error line marked with an asterisk):

DataSet ds = new DataSet();
ds.ReadXml(@"D:\Data\test.xml", XmlReadMode.ReadSchema);

foreach (DataTable table in ds.Tables)
{

for (int index = 0; index <= table.Rows.Count; index++)
{

{
SqlCommand command = new SqlCommand("ImportData", conn);
command.CommandType = CommandType.StoredProcedure;
adapter.InsertCommand = command;

SqlParameter param;

param = command.Parameters.Add("@columnID",
SqlDbType.UniqueIdentifier);
* param.Value = new
Guid(table.Rows[index].ItemArray["ColumnName"].ToString());
}
}
}

Did I do something wrong that I am not seeing, or is there another way to
reference a column?


Sep 5 '06 #4
Thanks, that helps a lot...especially in knowing why it did not work.

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

This should not have worked in the command window.

The reason it fails when you compile is because the ItemArray property
returns an array of values representing the row. Arrays are indexed on
integers, not strings, which is why you can't compile it.

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

"Mike Collins" <Mi*********@discussions.microsoft.comwrote in message
news:25**********************************@microsof t.com...
This worked in the command window while in debug mode

?table.Rows[0].ItemArray["ColumnName"].ToString()
"f0165f94-648f-4997-b578-11d89c8b1f61"

But gives the error below when I compile.

Cannot implicitly convert type 'string' to 'int' and the word ColumnName
is
underlined.

Here is a code snippett (with error line marked with an asterisk):

DataSet ds = new DataSet();
ds.ReadXml(@"D:\Data\test.xml", XmlReadMode.ReadSchema);

foreach (DataTable table in ds.Tables)
{

for (int index = 0; index <= table.Rows.Count; index++)
{

{
SqlCommand command = new SqlCommand("ImportData", conn);
command.CommandType = CommandType.StoredProcedure;
adapter.InsertCommand = command;

SqlParameter param;

param = command.Parameters.Add("@columnID",
SqlDbType.UniqueIdentifier);
* param.Value = new
Guid(table.Rows[index].ItemArray["ColumnName"].ToString());
}
}
}

Did I do something wrong that I am not seeing, or is there another way to
reference a column?


Sep 5 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Lauren Quantrell | last post: by
5 posts views Thread by simon | last post: by
9 posts views Thread by Andy Sutorius | last post: by
6 posts views Thread by compboy | last post: by
3 posts views Thread by Shawn Ferguson | last post: by
9 posts views Thread by Marco Nef | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.