473,383 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Datarow.setvalue maybe simple but

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
3 3088
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gregory.Spencer | last post by:
Help, I have a query in MySQL which gets the details of members of a club. e.g. Select * from members. however, in the same query I want to return the amount of "functions" the member has...
2
by: Jean | last post by:
Hello Guys, I need to set a default value in the first column of my dataTable. I tried to do it: foreach (DataRow rowExp in tblExport.Rows) { rowExp.ItemArray.SetValue("false", 0); }
0
by: Tal Sharfi | last post by:
Hi everyone I recently had the need for StringGrid object same as the one that Delphi has. An object that helps show lists of other objects in a simple grid. I searched the news groups and...
1
by: Jenny | last post by:
Hi all how can I place text in a new line (a break) if I'm showing text in a Label?? Thanks Jenny
25
by: MadCrazyNewbie | last post by:
Hey Group, Im Sure this is simple but I carn`t seem to find any info anywhere:( I have 2 x Forms: Form 1 has a DataConnecter and several DataAdapters on it, all bound together in my DataSet. ...
1
by: Ryan Liu | last post by:
Hi, Is there better way to find the DataRow associate with row of a datagrid? Now I put ID column(PK) as a column in a datagrid, and get this cell value of the datagrid current row...
5
by: David Smithz | last post by:
Hi there, From a customer database table, I need to get a list of all the customers that have the same birthdays and their names. While I can get a count of this and the name of one of the...
10
by: Nemisis | last post by:
HI everyone, I think i am on the right path but if someone could confirm it, that would be great. In my business Layer i have my business object, for this example, called User. User has...
5
by: Jelle | last post by:
Please, can anyone tell me, why this does not work: (I am a beginner) Imports system.web.ui.Webcontrols Dim ctrl As webcontrol Dim str as string For Each ctrl In me.Controls
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.