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.ItemArray[0];
}
it gives me this error: Specified cast is not valid.
When i try this: Convert.ToInt32(dstTopics.Tables[0].Rows.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 helplogic for this line has a problem.
CatRow["CategoryID"] = (int)dstTopics.Tables[0].Rows.ItemArray[0];
What are you trying to do??
-Takwell i'm trying to do is to insert a new row in Dataset table, i made it in VB.NET and it works pretty fine, but in C#, i'm stuck with that problemreplace the line with this,
from
CatRow["CategoryID"] = (int)dstTopics.Tables[0].Rows.ItemArray[0];
to
CatRow["CategoryID"] = ((int)(dstTopics.Tables[0].Rows.ItemArray[0]));
I think the problem is, you are not casting the 0th element of ItemArray, you were casting Rows...
-TakThank you alot, but the problem still existWhen i tried to cast to string it worked fine
string curCat;
curCat = (string)dstTopics.Tables[0].Rows.ItemArray[0];
and i tried what you told but it didnt work
CatRow["CategoryID"] = ((int)dstTopics.Tables[0].Rows.ItemArray[1]);
note: it was wrong when i wrote itemArray[0] first time, it was ItemArray[1]Ok, try this,
ItemArray returns a type Object. And I dont think, Convert.ToInt32 takes an Object type as param, you will probabaly have to do a Convert.ToInt32(.....ItemArray[0].ToString());
tak
[EDIT]
P.S. Without casting it, if you try to print it out on the screen, does anything display?
and why dont you do a TypeOf and display the type?
B/c the issue is with casting, if you can find out what is ItemArray[0] is actually holding, that will help.
takWhen i tried to cast to string it worked fine
string curCat;
curCat = (string)dstTopics.Tables[0].Rows.ItemArray[0];
and i tried what you told but it didnt work
CatRow["CategoryID"] = ((int)dstTopics.Tables[0].Rows.ItemArray[1]);
note: it was wrong when i wrote itemArray[0] first time, it was ItemArray[1]
Did you try this?
CatRow["CategoryID"] = ((int) (dstTopics.Tables[0].Rows.ItemArray[1]) );Yes sir same problem, can you show me how to use typeof?!Heeeeeeeeeey, can anybody tell me how to use it?! and this thread is not complete yet!!! hi.
Use GetType.ToString to get the type of that obj.
like, Button b;
label1.text = b.GetType.ToString
tak
for (i = 0; i < dstTopics.Tables[0].Rows.Count; i++)
{
DataRow CatRow = dstTopics.Tables[0].NewRow();
CatRow["CategoryID"] = (int)dstTopics.Tables[0].Rows.ItemArray[0];
}
it gives me this error: Specified cast is not valid.
When i try this: Convert.ToInt32(dstTopics.Tables[0].Rows.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 helplogic for this line has a problem.
CatRow["CategoryID"] = (int)dstTopics.Tables[0].Rows.ItemArray[0];
What are you trying to do??
-Takwell i'm trying to do is to insert a new row in Dataset table, i made it in VB.NET and it works pretty fine, but in C#, i'm stuck with that problemreplace the line with this,
from
CatRow["CategoryID"] = (int)dstTopics.Tables[0].Rows.ItemArray[0];
to
CatRow["CategoryID"] = ((int)(dstTopics.Tables[0].Rows.ItemArray[0]));
I think the problem is, you are not casting the 0th element of ItemArray, you were casting Rows...
-TakThank you alot, but the problem still existWhen i tried to cast to string it worked fine
string curCat;
curCat = (string)dstTopics.Tables[0].Rows.ItemArray[0];
and i tried what you told but it didnt work
CatRow["CategoryID"] = ((int)dstTopics.Tables[0].Rows.ItemArray[1]);
note: it was wrong when i wrote itemArray[0] first time, it was ItemArray[1]Ok, try this,
ItemArray returns a type Object. And I dont think, Convert.ToInt32 takes an Object type as param, you will probabaly have to do a Convert.ToInt32(.....ItemArray[0].ToString());
tak
[EDIT]
P.S. Without casting it, if you try to print it out on the screen, does anything display?
and why dont you do a TypeOf and display the type?
B/c the issue is with casting, if you can find out what is ItemArray[0] is actually holding, that will help.
takWhen i tried to cast to string it worked fine
string curCat;
curCat = (string)dstTopics.Tables[0].Rows.ItemArray[0];
and i tried what you told but it didnt work
CatRow["CategoryID"] = ((int)dstTopics.Tables[0].Rows.ItemArray[1]);
note: it was wrong when i wrote itemArray[0] first time, it was ItemArray[1]
Did you try this?
CatRow["CategoryID"] = ((int) (dstTopics.Tables[0].Rows.ItemArray[1]) );Yes sir same problem, can you show me how to use typeof?!Heeeeeeeeeey, can anybody tell me how to use it?! and this thread is not complete yet!!! hi.
Use GetType.ToString to get the type of that obj.
like, Button b;
label1.text = b.GetType.ToString
tak