473,566 Members | 2,784 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 DataTempDataCon text
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 4541
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.co m>
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 DataTempDataCon text
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
2067
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"; and another variable: $name = "Epson"; Then you can refer to $name, or $$var. They will equal the same thing.
15
10843
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 very well. We are now adding a lot more functionality to our filters and could really benefit from using the LINQ to SQL. I have experimented with...
7
2660
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 programming, just with a different data getting process...
4
4465
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 other. I need to copy all the relationships too. Thanks for any help, I really appreciate it. Thanks,
3
2889
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: tlkpColor (PK) tlkpColorID
2
4792
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 table names might include "SomeTable1" or "SomeTable236" etc... Unfortunately when I try to use something like "from SomeTable +...
2
4465
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 name="item1">value1</ item><item name="item2">value2</item></data></datas> ......
2
3291
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 this work:
0
984
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
7666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7888
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8108
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7951
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.