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

Datarow.setvalue maybe simple but

P: n/a
Hello,

I am trying to add some kind of counter in a datatable, i use SetValue but
it don't semm to work.

Here is the code

System.Data.DataSet dsClubs = new System.Data.DataSet();

monDA.Fill(dsClubs, "Clubs");

//Ajout de la colonne Nombre de combattants par club

System.Data.DataColumn cNbrComp = new System.Data.DataColumn();

cNbrComp.ColumnName = "NbCompetiteur";

cNbrComp.DefaultValue = 0;

cNbrComp.DataType = System.Type.GetType("System.Int32");

dsClubs.Tables["Clubs"].Columns.Add(cNbrComp);

// Définition de la clé primaire

System.Data.DataColumn[] cles = new System.Data.DataColumn[1];

cles[0] = dsClubs.Tables["Clubs"].Columns[0];

dsClubs.Tables["Clubs"].PrimaryKey = cles;


// Récupération du nombre de combattants par clubs

for (int i=0;i<monDS.Tables["Competiteur"].Rows.Count;i++)

{

System.Data.DataRow tempLigne =
dsClubs.Tables["Clubs"].Rows.Find(monDS.Tables["Competiteur"].Rows[i].ItemArray[5])
;

// I Search for a spécific Row in Clubs, it works fine, but the next line
don't seem to work, as the value stay to 0

tempLigne.ItemArray.SetValue( (int) (tempLigne.ItemArray.GetValue(2)) + 1,
2);

System.Windows.Forms.MessageBox.Show(tempLigne.Ite mArray[2].ToString());

}
The Column is not in Readonly, so i should be able to modify it no ?

Thanks for your answers.

Michael
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Michael,

When I see your code than I get the idea that you are searching for
something that is easy to find using the dataview.find. Can you explain what
you try to achieve?

I assume that you don't set that value for nothing, there must be a reason
for that..

Cor
Nov 16 '05 #2

P: n/a
I have a list of persons (Tables["Competiteur"]) who belongs to some judo
clubs, in this list i will have maybe 5 people from 1 club, 3 from an other,
and 2 from again an other one.

I have also a Table (Tables["Clubs"]) with the list of all Clubs possible.

And i want for the purpose of another algorithm, to know for each club how
many people i have in the previous list.

So i get the Dataset corresponding to the Clubs Table, i had a column which
will be my counter "NbCompetiteur", i set the default value to 0.

I look now at the list of people, and for each club i want to increment the
counter, that's why i use the Find method, and the the SetValue method.

Whith This i have the correct value : 1 (0 +1)
(int) (tempLigne.ItemArray.GetValue(2)) + 1

But i cannot Put this with the SetValue method, it don't seem to work.

I hope it is a little bit clearer.

"Cor Ligthert" <no************@planet.nl> a écrit dans le message de news:
%2****************@TK2MSFTNGP10.phx.gbl...
Michael,

When I see your code than I get the idea that you are searching for
something that is easy to find using the dataview.find. Can you explain
what you try to achieve?

I assume that you don't set that value for nothing, there must be a reason
for that..

Cor

Nov 16 '05 #3

P: n/a
Michael,

You can use the datarelation for this or the dataview. Where I would take
the dataview
Roughly typed

\\\
DataView dv = new DataView(....Tables["Persons"]);
dv.RowFilter = "ClubName = '" + (....Tables["Clubs"].Rows[x]["ClubName"] +
"'"
int persons = dv.count;
///

I hope I understood you well

There are more methods by instance the datatable select which gives you a
collection of affected datarows and which you can use almost the same as
above.

Cor
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.