Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Could anyone please suggest, I have a datatable with 100 records and want to update any 1 specific record based on id.
Here is an example, maybe it helps even if your reqirement is not that clear:
DataRow row = tableWith100Rows.AsEnumerable()
.FirstOrDefault(r => r.Field<int>("ID") == 4711);
if(row != null)
row.SetField("ColumnToUpdate", "new value");
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Currently, I have a List<object> like this: List<USER>.
In User class, I have column named UserName.
I want to retrieve this column to List<string>.
How can it work without using foreach for List<USER>?
Thanks.
You can use LINQ:
List<string> userNames = users.Select(u => u.UserName).ToList();
In addition to Tim Schmelter post:
For casting IEnumerable<object> to IEnumerable<USER> you may use Cast<T> or OfType<T> method.
This can be written as follows:
var userNames = users.Cast<USER>.Select(u => u.UserName).ToList();
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have created JSON using following code.
List<int> _data = new List<int>();
foreach (DataRow row in dt.Rows)
{
_data.Add((int)row["Id"]);
}
JavaScriptSerializer jss = new JavaScriptSerializer();
chartData = jss.Serialize(_data);
Now can anyone tell me how do I save this is something like data.json? I want to write it into a file.
The Serialize method returns a String, doesn't it? So you can just use File.WriteAllText().
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
select cast(' ' as varchar(1000)) as myfield, otherfield
from tab1;
I need to convert above SQL to Linq-To-Sql.
Maybe:
from item in dataContext.Items
select new { MyField = "", Item = item };
Unfortunately, AMAIK, there is no way to declare * in projection in LINQ. Thus to have all other fields alongside your MyField field, you should write them all.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Select * from table
where Numero_Operacion in
(
Select Numero_Operacion from table
group by Numero_Operacion
having count(Numero_Operacion)>1
)
THANKS!
It would be something like this
<Table>.GroupBy(x => x.Numero_Operacion)
.Where(x => x.Count() > 1)
.SelectMany(x => x)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a combobox, and I would like to search through every element in it.
How can I do this? (also the number of items is not the same everytime, but this is not so important).
I am using c# windows form application.
you can do this
for (int i = 0; i < myComboBox.Items.Count; i++)
{
string value = myComboBox.GetItemText(myComboBox.Items[i]);
}
Use a foreach loop. It will iterate all your items of ComboBox regardless of their count, e.g.
foreach(var item in myComboBox.Items)
{
// do something with your item
}