Updating A LINQ Query

jsurpless

Well-known member
Joined
Jul 29, 2008
Messages
144
Programming Experience
Beginner
Hi

I've got this LINQ query

VB.NET:
Dim WindowAlarmList_Table_Query = From Alarm_Record As DataRow In WindowAlarmList_Table.AsEnumerable _
                                                  Select Alarm = Alarm_Record.Field(Of String)("Alarm"), _
                                                         Window = Alarm_Record.Field(Of String)("Window") _
                                                  Where Alarm = strCompoundBlock

I would like to be able to update a particular field but am having trouble... in the past, I have done


VB.NET:
Dim WindowAlarmList_Table_Query = From Alarm_Record As DataRow In WindowAlarmList_Table.AsEnumerable Select Alarm_Record _
                                                  Where Alarm = strCompoundBlock

and I am able to update because Alarm_Record is a DataRow and I can use .BeginEdit... but above, it's anonymous...

Is there a way to update using the 1st syntax or do I have to use the 2nd?

Thanks!

-Justin
 
You already have the syntax. You just posted it yourself. LINQ is about getting data, not changing it. Once you've used LINQ to get that data, what you do with it is up to you. A list you get from a LINQ query is the same as any other list, so if you want to modify the data in it you do so like you would for any other list.
 
You already have the syntax. You just posted it yourself. LINQ is about getting data, not changing it. Once you've used LINQ to get that data, what you do with it is up to you. A list you get from a LINQ query is the same as any other list, so if you want to modify the data in it you do so like you would for any other list.

OK, but if I try to set Alarm_Record.Alarm - I am told that it is a read-only property... and I don't seem to have any other way to access the fields because Alarm_Record.Field isn't valid...
 
That's got nothing to do with LINQ. Alarm_Record is a DataRow so it has the same set of properties no matter how you come by it. Anyway, DataRow has no Alarm property. A typed DataRow might but you haven't declared it as a typed DataRow.

As for Field, it is a method, not a property, so you can't set it. It returns the value of the specified field. If you want to set the specified field then you call the SetField method.
 
Back
Top