String foreach problem

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi guys, i hace a question

i have a datagrid

col1 col2
-----------------
D text0
text1
text2
D text3
D text4

i need to do a foreach and everywhere where's a "D" in col1 to add the
value of col2 into a string, so the final string would be "text0" +
"," + "text3" + "," + "text4";

for example:

string Uvjet()
{
foreach (DataRow red in dt.Rows)
{
if (red["col1"].ToString() == "D")
{
string uvjet = red["col2"].ToString() + ",";
}
}
return uvjet;
}


...only this fills the string "uvjet" only with one value....and i want
it to be finally filled with all necessary values, like:
"text0" + "," + "text3" + "," + "text4"

if you have any ideas, please help...
THANX!

.



Relevant Pages

  • Re: String foreach problem
    ... Your code appears to be using a DataTable, not a DataGrid. ... i need to do a foreach and everywhere where's a "D" in col1 to add the ... value of col2 into a string, so the final string would be "text0" + ... He is also correct that your code doesn't compile (since you use "uvjet" outside of the code block in which it's declared). ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: String foreach problem
    ... foreach ... string Uvjet() ... string uvjet = string.Empty; ... This ONLY adds a semi-colon on iterations after the first iteration. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: String foreach problem
    ... i need to do a foreach and everywhere where's a "D" in col1 to add the ... value of col2 into a string, so the final string would be "text0" + ... string Uvjet() ... This is however a good example where concatenating strings is a bad idea. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: System.AccessViolationException
    ... internal string theAP; ... DataColumn col = new DataColumn; ... private string _pwd; ... foreach ...
    (microsoft.public.dotnet.languages.csharp)
  • Access denied
    ... First it builds wsdl string: ... foreach ... CSharpCodeProvider cscp = new CSharpCodeProvider; ... CompilerParameters cp = new CompilerParameters; ...
    (microsoft.public.dotnet.languages.csharp)