Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 3.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-28-2005, 08:09 PM   PM User | #1
Cipher
Regular Coder

 
Cipher's Avatar
 
Join Date: Dec 2004
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
Cipher is an unknown quantity at this point
Another C# problem

Why this's not working: (this's not the full code).

for (i = 0; i < dstTopics.Tables[0].Rows.Count; i++)
{
DataRow CatRow = dstTopics.Tables[0].NewRow();
CatRow["CategoryID"] = (int)dstTopics.Tables[0].Rows[i].ItemArray[0];
}


it gives me this error: Specified cast is not valid.
When i try this: Convert.ToInt32(dstTopics.Tables[0].Rows[i].ItemArray[0])

it gives me this error: Input string was not in a correct format.

when i try not using any cast type, it gives looooooooooooong error statment,
Thanks too much for help
__________________
i need a creative atmosphere
Cipher is offline   Reply With Quote
Old 10-28-2005, 10:11 PM   PM User | #2
kampfer
New Coder

 
Join Date: Oct 2005
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
kampfer is an unknown quantity at this point
what are you tring to do? What information is going into CatRow["CategoryID"]?

-john
kampfer is offline   Reply With Quote
Old 10-28-2005, 10:53 PM   PM User | #3
Cipher
Regular Coder

 
Cipher's Avatar
 
Join Date: Dec 2004
Posts: 123
Thanks: 0
Thanked 0 Times in 0 Posts
Cipher is an unknown quantity at this point
The CategoryID from the DataSet table and sure its integer, when i used the casting before with string it worked fine
string curCat;
curCat = (string)dstTopics.Tables[0].Rows[i].ItemArray[0];


i also tried to save the CategoryID in variable first but it didnt work.
__________________
i need a creative atmosphere
Cipher is offline   Reply With Quote
Old 10-28-2005, 11:10 PM   PM User | #4
kampfer
New Coder

 
Join Date: Oct 2005
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
kampfer is an unknown quantity at this point
try this:

// create a datatable
DataTable myTable = new DataTable("tablename");

// create a column
DataColumn dcCategoryID = new DataColumn("Item ID", Type.GetType("System.Int32"));

// add column to datatable
myTable.Columns.Add(dcCategoryID);

// create an array
object [] myArray = new object[1];

// populate array
DataRow dr;
for(int i = 0; i < 4; i++)
{
myArray[0]= "item id " + i;
dr = dt.NewRow();
dr.ItemArray = myArray;
myTable.Rows.Add(dr);
}

// display the table
foreach(DataRow myRow in myTable.Rows)
{
foreach(DataColumn myColumn in myTable.Columns)
{
Console.WriteLine(myRow[myColumn]);
}
}

-john
kampfer is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:30 PM.


Advertisement
Log in to turn off these ads.