Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,
i have a dataset in which i get more than 1 values like Itemdescription and its Quantity,
and that (Itemdescription,Quantity) i pass to another Method
Send_Mail(Itemdescription,Quantity)...but while sending the values i m only getting 1 value not the other's.
following is the code:
C#
for (int j = 0; j <= dsTotalQuantity.Tables["TotalUnitsRequired"].Rows.Count; j++)
   {
   MaterialDescpt = ds.Tables["TotalUnitsRequired"].Rows[j]["MaterialDesc"].ToString();
   TotalUnitsRequired = ds.Tables["TotalUnitsRequired"].Rows[j]["TotalUnitsRequired"].ToString();
   }

Send_Mail(MaterialDescpt,TotalUnitsRequired);


what could be done!!!

Regards,
Aamir

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 29-Jun-12 19:11pm
v2

1 solution

When you run code like that in a loop, you overwrite the string each time you loop round. Either use the "+=" operator instead:
C#
for (int j = 0; j <= dsTotalQuantity.Tables["TotalUnitsRequired"].Rows.Count; j++)
   {
   MaterialDescpt += ds.Tables["TotalUnitsRequired"].Rows[j]["MaterialDesc"].ToString();
   TotalUnitsRequired += ds.Tables["TotalUnitsRequired"].Rows[j]["TotalUnitsRequired"].ToString();
   }

Send_Mail(MaterialDescpt,TotalUnitsRequired);
Or better, use a StringBuilder:
C#
StringBuilder sbMat = new StringBuilder();
StringBuildersbTot = new StringBuilder();
for (int j = 0; j <= dsTotalQuantity.Tables["TotalUnitsRequired"].Rows.Count; j++)
   {
   sbMat.Append(ds.Tables["TotalUnitsRequired"].Rows[j]["MaterialDesc"].ToString());
   sbTot.Append(ds.Tables["TotalUnitsRequired"].Rows[j]["TotalUnitsRequired"].ToString());
   }

Send_Mail(sbMat.ToString(),sbTot.ToString());
You may also want to add some separator characters in there...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900