473,500 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Refer to LINQ Field name as Variable

LINQ works a lot like an Access DB Recordset in the way it functions, one of
the things I could do in Access is refer to the Fields thru a Variable as
below allowing me to Iterate over the Recordset with a test or slight change
to field names. Is there a way to Replicate this Method in LINQ, I've tried
setting the Variable as an Object "Dim tDayID AS Object = "tem.Day" & 1" but
it did not work?

IN ACCESS:
Dim DaI As String
DaI = "DayID" & 1

For da = 1 To 7
With RS1
If RS2.Fields(DaI) <0 Then
.Edit
Else
.AddNew
End If
!TimeValue = RS2.Fields("Day" & da)
!DayDate = dat
!Locked = False
!MemoNote = RS2.Fields("M" & da)
!LogID = RS2!GroupID
.Update
End With
Next da

Here is a snippet of the LINQ where I would like the tDayID to be the
Variable of LINQ Field and get its Value for testing (Code snippet not
Complete just a Sample):

Dim tDayID As Object
Dim dbTemp As New DataTempDataContext
Dim GetTemp = (From tem In dbTemp.tblTemps _
Where tem.EmployeeID = Me.HiddenEmplID.Value _
Select tem)

'Iterate over Temp Table records to Update Existing TimeRecord
For Each tem In GetTemp
tDayID = "tem.Day" & 1
da = 0

For da = 1 To 7 'Iterate over Temp Days to write Time Values to
Time Record
For Each ti In time 'Iterate over TimeRecord Table records
to find match

'HERE IS WHERE THE FIELD VARIABLE IS USED AND WOULD BE RESET DURING LOOP
If ti.DayID = tDayID Then
ti.ClientID = tem.ClientID
ti.ClientDesc = tem.Client
ti.LogID = tem.LogID
ti.PeriodID = tem.PeriodID
ti.ProjectDesc = tem.Project
ti.ProjectID = tem.ProjectID
ti.Task = tem.TaskID
ti.TaskDesc = tem.Task
ti.DayDate = dat
ti.TimeValue = tem.Day1
ti.Memo = tem.M1
ti.DayID = tDayID
End If
Next
Next da
Next
Jan 23 '08 #1
1 4536
Hi John,

As for the Access variable feature you mentioned, I'm afraid the .NET LINQ
to SQL expression or engine can not directy support this. Because the LINQ
expression/query are parsed and compiled at compile time, and it should get
all the type information rather than change or determine them at
runtime(when executing). This is different from access which use VBA which
is a dynamically execution/late binding code.

therefore, for LINQ code, I would always suggest you use a property from a
definted data object.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "john" <no**@none.com>
Subject: Refer to LINQ Field name as Variable
Date: Wed, 23 Jan 2008 03:54:37 -0500
>
IN ACCESS:
Dim DaI As String
DaI = "DayID" & 1

For da = 1 To 7
With RS1
If RS2.Fields(DaI) <0 Then
.Edit
Else
.AddNew
End If
!TimeValue = RS2.Fields("Day" & da)
!DayDate = dat
!Locked = False
!MemoNote = RS2.Fields("M" & da)
!LogID = RS2!GroupID
.Update
End With
Next da

Here is a snippet of the LINQ where I would like the tDayID to be the
Variable of LINQ Field and get its Value for testing (Code snippet not
Complete just a Sample):

Dim tDayID As Object
Dim dbTemp As New DataTempDataContext
Dim GetTemp = (From tem In dbTemp.tblTemps _
Where tem.EmployeeID = Me.HiddenEmplID.Value _
Select tem)

'Iterate over Temp Table records to Update Existing TimeRecord
For Each tem In GetTemp
tDayID = "tem.Day" & 1
da = 0

For da = 1 To 7 'Iterate over Temp Days to write Time Values
to
>Time Record
For Each ti In time 'Iterate over TimeRecord Table records
to find match

'HERE IS WHERE THE FIELD VARIABLE IS USED AND WOULD BE RESET DURING
LOOP
If ti.DayID = tDayID Then
ti.ClientID = tem.ClientID
ti.ClientDesc = tem.Client
ti.LogID = tem.LogID
ti.PeriodID = tem.PeriodID
ti.ProjectDesc = tem.Project
ti.ProjectID = tem.ProjectID
ti.Task = tem.TaskID
ti.TaskDesc = tem.Task
ti.DayDate = dat
ti.TimeValue = tem.Day1
ti.Memo = tem.M1
ti.DayID = tDayID
End If
Next
Next da
Next
Jan 24 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2057
by: Epson Barnett | last post by:
Hi, I'm new to C# and I'd like to be able to reference a field of an object using a variable instead of literal text. In the PHP scripting language, you can create a variable: $var = "name";...
15
10828
by: EDBrian | last post by:
My problem is this. Our clients create different fields they want to collect and we allow them build dynamic filters, reports etc... We run some TSQL to actually create the column and all works...
7
2650
by: Andy B | last post by:
Just wondering why linq is more useful than datasets? The stuff I do doesn't seem to be too complicated to use linq with it. If I did use linq with it now, I would be doing almost the exact same...
4
4445
by: =?Utf-8?B?Tmljaw==?= | last post by:
Hello, I'm using LINQ to access a SQL Server database. The user needs to be able to duplicate a record. Is there an easy way to do this? I rather not have to set each property from one to the...
3
2877
by: Leo Seccia | last post by:
Hello everyone, I have a c# project with a sql server database. I have a number of lookup tables in my database which I successfully managed to import into my LINQ dataclasses. eg. Table:...
2
4784
by: Joey | last post by:
I am querying a DataSet with LINQ. I am running into a problem when trying to construct my query because in the "from" clause I do not know the table name (range variable) until runtime. Possible...
2
4460
by: timor.super | last post by:
Hi group, In my database, I have a table with fields like this : id | title | xml ------------------------------------ 1 | title1 | <datas><data><item...
2
3283
by: jelle79 | last post by:
Hi all, I'm storing all kind of data stored in objects. Now I want to query my data-source. And I thought LINQ is the right thing for it. Data is stored like: store.Database Queries like...
0
977
by: kkrylov | last post by:
Hi, I am trying to work with XML that looks like this; <?xml version="1.0" encoding="UTF-8" ?> <Batch> <Page> <Field> <Name>Manifest</Name> <Value>200520000</Value> </Field>
0
7136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7232
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6906
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7397
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5490
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4611
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.