this is the importent part of my code DataSet HexDS = new DataSet(); DataTable HexTable = HexDS.Tables.Add(); HexTable.Columns.Add("ID", typeof(double)); HexTable.Columns.Add("Answer", typeof(double)); HexTable.Rows.Add(x, 1); y++; if (y >=1) { here i want to add one to the row with ID x(wich canbe any number because of the code i used before the piece i show you now)in the collumn Answer } i dont know the index too because this will be repeating with different x en y values in the same session my question is how can i do this?
Jelte12345 Thursday, October 01, 2009 10:51 AM
Hi,
Sorry for some little syntax mistakes
Here is the working code.
DataRow[] drArr = HexTable.Select("Id=" + x);//+ was missing
drArr[0][
"Answer"]=Convert.ToDouble(drArr[0]["Answer"])+1; //selecting the rows is not necessary again
Marked As Answer byJelte12345Thursday, October 01, 2009 7:47 PM
Tamer Oz Thursday, October 01, 2009 4:10 PM
I think this is what you are looking for.
DataRow[] drArr=HexTable.Select("Id=" x);//select the rows with Id =x drArr[0]["Answer"]=Convert.ToDouble(HexTable.Select("Id=" x)[0]["Answer"])+1//assign the value back to Answer column of the first row by increasing 1
Unmarked As Answer byJelte12345Thursday, October 01, 2009 3:14 PM
Marked As Answer byJelte12345Thursday, October 01, 2009 12:12 PM
Tamer Oz Thursday, October 01, 2009 11:08 AM
so i don't have to say that the HexTable is part of the HexDS Dataset?
Jelte12345 Thursday, October 01, 2009 12:16 PM
No. It is associated when you declare.
Tamer Oz Thursday, October 01, 2009 12:23 PM
I think this is what you are looking for.
DataRow[] drArr=HexTable.Select("Id=" x);//select the rows with Id =x drArr[0]["Answer"]=Convert.ToDouble(HexTable.Select("Id=" x)[0]["Answer"])+1//assign the value back to Answer column of the first row by increasing 1
when i copy paste this code and change Id in ID and change x into the variable i want it to be i get two errors:
the things wich are big was the error line under
DataRow[] drArr=HexTable.Select("Id=" x);
there it says : ") expected" i realy don't understand why he is saying that so i guess there is actually something else wrong
here it says: "Only assignment, call, increment, decrement, and new object expressions can be used as a statement" i also don't understand this one so could anyone please tell me if there is something wrong with the piece of code Tamer Oz gave me?
and i don't know if this is important but i'm using Visual C# 2008 Express edition
Jelte12345 Thursday, October 01, 2009 3:13 PM
Hi,
Sorry for some little syntax mistakes
Here is the working code.
DataRow[] drArr = HexTable.Select("Id=" + x);//+ was missing
drArr[0][
"Answer"]=Convert.ToDouble(drArr[0]["Answer"])+1; //selecting the rows is not necessary again
Marked As Answer byJelte12345Thursday, October 01, 2009 7:47 PM