Dynamically Select Table At Runtime With Dynamic LINQ?

Feb 17, 2011

I'm developing an application to allow engineers to conduct simple single table/view queries against our databases by selecting Database, Table, Fields.

I get how to use the Dynamic LINQ Library Sample to provide for dynamically selecting the Select, Where and Order by Clauses at runtime but I'm at an impass on how to allot for table choice.

Is there a way to provide for dynamically selecting the "from" table at run time

EDIT

So Both of the answers seem to be saying the same general Idea. I'm going to try to convert the C# into VB and get it to work.

The first answer converts to

NotInheritable Class DataContextExtensions
Private Sub New()
End Sub

[Code].....

View 2 Replies


ADVERTISEMENT

Dynamic - Dynamically Add Div Table Rows

May 29, 2009

Im a VB.NET beginnger, how I can dynamically add a div table row or how I can loop a section of html?

View 1 Replies

Dynamic Variables In Linq Select Statement?

Nov 23, 2009

I have a listbox that is dynamically filled by certain values depending on what table has been selected from another list box. Once a value is selected, it is being graphed vs a date & time range. With my ignorance of linq: depending on what value is selected, the linq to sql statement I need to create to grab data from my database is different as I can't use an index on an anonymous type.

result = From t In db.APS _
Where t.DateTime >= startDate And _
t.DateTime <= finishDate And t.Weight = weight _
Select t.DateTime, t.TotalConcentration

t.TotalConcentration should be selected if my listbox value is "Total Concentration", but if it's something else, like "Temperature" or "Flow Rate" (connected to appropreate database columns) - this method obviously isn't going to work. I need to be able to dynamically select a specific column from the anonymous type list, or use some other method I'm unaware of to do this.

View 1 Replies

[2008] Dynamic LINQ Queries And Select Statements?

Jun 5, 2008

I've recently ported my website from 2005 to 2008, and I'm using LINQ Queries to implement a search. The issue is that none of the fields are mandatory, so I've had to implement a dynamic LINQ Query (sic?). Here's the relevant code -

Public Function searchQuery(ByVal titleType As String, ByVal titleName As String, _
ByVal configMgr As String, ByVal lifecycle As String, _
ByVal CIType As String, ByVal recordsPerPage As String) As IEnumerable(Of

[code].....

View 2 Replies

C# - LINQ To SQL Join Two Tables To Select Parent Table Twice Based On Two Different Columns From Child Table?

Aug 23, 2010

I have two tables Employees and CafeLogs. Some employees can be cashiers and also customers at the Cafe shop.

Table structures:

Employees: EmployeeId(PK) , FirstName, LastName
CafeLogs: LogId (PK), CashierId, EmployeeId, Value, => CashierId and EmployeeId are the data from column EmployeeId of Empoyee table

Table relationship:

Employees 1:N CafeLogs (CashierId (FK))

[code]....

Right now I know how to select only LogId, Employee's name, and , Value, not with Cashier name yet.

Dim query = From log In db.CafeLogs _
Join emp In db.Employees On emp.EmployeeId Equals log.EmployeeId _
Select log.LogId, emp.FirsName, emp.LastName, log.Value

View 1 Replies

C# - Use Meta Tales Or Table Names To Construct A Dynamic Query In LINQ?

Feb 8, 2011

Is there a way to use Meta Tales or Table names to Construct a dynamic query in LINQ?

foreach (var metaTable in db.Mapping.GetTables())
{
var queryType = metaTable.RowType.Type;

[code]....

Is there a way to do something like this? The attempt above yields the error:Could not find an implementation of the query pattern for source type 'System.Data.Linq.ITable'. 'Select' not found. Consider explicitly specifying the type of the range variable 'q'.

View 2 Replies

Convert A Two-table Exists Query From SQL To Linq Using Dynamic Fields In The Subquery?

Jun 7, 2011

I'm trying to query old Access database tables and compare them with SQL Server tables.They often don't have primary keys, or they have extra fields that had some purpose in the nineties, etc., or the new tables have new fields, etc.I need to find records - based on a set of fields specified at runtime - that are in one table but not another.So, I do this kind of query all the time in SQL, when I'm comparing data in different tables:

dim fields_i_care_about as string = "field1, field2, field3"
'This kind of thing gets set by a caller, can be any number of fields, depends on the
'table
dim s as string= ""

[code]....

It tells me it can't convert a Boolean - Is there any way to do this without Linq expressions? They seem far more complex than what I'm trying to do here, and they take a lot of code, and also I can't seem to find examples of Expressions where we're comparing two fields in a subquery.Is there a simpler way? I know I could do the usual EXISTS query using JOIN or IN - in this case I don't need the query to be super fast or anything. And I don't need to use a DataTable or DataSet - I can put the data in some other kind of object.

View 1 Replies

Asp.net - Select Query In LINQ Based On Foreign Table

Mar 2, 2011

I have 2 Tables , OrderDetails and Requests In my LINQ to SQL dbml file. OrderDetailsID is a foreign key in Requests Table.

I want to write the query to get the sum of UnitCost from OrderDetails based on OrderId. And If there is a row in Requests Table for each OrderDetailsID, and the Requests.Last.RequestType="Refund" I want to reduce the total refund amount from the main sum otherwise If there is no row based on OrderDetailsID, add to sum.

Here is the way I implement that. I am looking to prevent using "For each".

iRefund = (From od1 In dc.OrderDetails _
Where od1.OrderID =1 _
Select od1.UnitCost).Sum

[Code]....

View 1 Replies

Select Query In LINQ Based On Foreign Table?

Mar 4, 2009

I have 2 Tables , OrderDetails and Requests In my LINQ to SQL dbml file.OrderDetailsID is a foreign key in Requests Table.I want to write the query to get the sum of UnitCost from OrderDetails based on OrderId.And If there is a row in Requests Table for each rderDetailsID, and the Requests.Last.RequestType="Refund" I want to reduce the total refund amount from the main sum otherwise If there is no row based on OrderDetailsID, add to sum

View 3 Replies

Dynamic LINQ Query Based On Dynamic Number Of Comboboxes?

Feb 5, 2010

I would like to bind a DataGridView to a different LINQ query every time (in order to reuse the same form/DGV for different queries), like this:

[Code]....

but the "Qry", and the number of comboboxes, and their field names would change every time.

View 5 Replies

Dynamic SQL To Dynamic LINQ In .NET With MS SQL Server 2008?

May 24, 2010

I need to represent the following query using LINQ:

DECLARE @PurchasedInventoryItemID Int = 2
DECLARE @PurchasedInventorySectionID Int = 0
DECLARE @PurchasedInventoryItem_PurchasingCategoryID Int = 3
DECLARE @PurchasedInventorySection_PurchasingCategoryID Int = 0

[code]....

Now, I know that a query in .NET doesnt look like this, this is my test in the SQL Design Studio. Naturally VB.NET variables will be used in place of the SQL local variables.My problem is this: All of the conditions after "WHERE" are optional. In that a query might be made that uses one, some, all, or none of the conditions. V.PropertyID and V.Value can also appear any number of times.In VB.NET I can make this query easy enough by simply concatenating strings, and using a loop to append the "V.PropertyID/V.Value" conditions.I can also make a Stored Procedure in MS SQL, which is easy enough.However, I want to accomplish this using LINQ.

View 2 Replies

How To Get Lamda In LINQ To Actually Filter For Dynamic Linq

Sep 10, 2009

Example-I have a person class

Public Class Person
Private _fname As String
Public Property Fname() As String

[Code]...

View 2 Replies

LINQ Query Using The Dynamic LINQ Library?

Mar 31, 2011

Forgive my ignorance on this.I have this LINQ Query:Dim ngBikersDataContext As New CarBikeWalkDataContext

bikersList = (From c In ngBikersDataContext.Reg_Bikers _
Order By c.L_Name _
Select New Bikers() With { _
.BikerID = c.BikerID, _
.F_Name = c.F_Name, _

[Code]...

with the error "Overload resolution failed because no accesible 'Select' accepts this number of arguments."
Over the "NEW" I get an error " ')'expected."

View 1 Replies

RowSpan On A Table Created Dynamically Located Inside Another Table?

Apr 24, 2009

I'm writing a scheduling program that queries a MySQL database for today's appointments and uses a Table Layout Panel with employees on the top and times on the left to display the schedule. I am trying to add another table ontop of that table for each appointment and set the rowspan of that dynamic table to occupy the time slot of that appointment from start to finish.ll the appointments appear in the dynamic table and each dynamic table appears in the appropriate starting positions in the main table. When you are designing GUI's and put a Table within a table, you get a RowSpan and ColumnSpan option for that inner table. The problem I'm having is the dynamic tables are not giving me a RowSpan option, which I believe is because it was created using code and doesn't know that it's inside another table.Here is part of the code... This code is inside loops for each appointment of each employee

sqlCustomer = MyReader.GetValue(0).ToString()
sqlCompany = MyReader.GetValue(1).ToString()
sqlProblem = MyReader.GetValue(2).ToString()

[code].....

View 5 Replies

Add Dynamic Control To Dynamically Added Picturebox?

Jan 19, 2011

how to add dynamic control to dynamically added picturebox?

View 3 Replies

Dynamic - Accessing Each Button's Properties After They Are Dynamically Generated?

Jun 11, 2012

I have used the following code to generate buttons dynamically. I want to know how to code in such a way that if i click one button, there should be some change done to some other button in the same form. Since all the buttons are generated in the loop, i do not know how to call one button elsewhere in the code.

Private Sub random2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer

[Code].....

View 1 Replies

Database - Visual Basic: Copying A Random Row From One Table Into Another Table At Runtime

May 16, 2011

I have a database that has two tables in it. One is a table of items (table1) and the other is the table of current items (table2).On form load I need to generate a random amount of the items from table1 and populate table2 with them. I was trying to do something like this:

[Code]...

View 2 Replies

Dynamic Where In Linq To SQL?

Sep 14, 2010

How would I get something like this to work so that I can dynamically alter the where-clause in this linq to sql query?

Dim AccountID = 1234
Dim AccountList
Select Case Types

[Code]....

With the above code I get this error:

Late binding operations cannot be converted to an expression tree

View 1 Replies

Add Dynamic Texbox In GridView At RunTime?

May 10, 2012

I would like to add controls like textBox in GridView from code on the fly.

In my project i have one Grid in that i can't decide how many rows and columns are there. so that i just give it DataSource. This working fine. [code]...

View 3 Replies

Constructing Dynamic Properties At Runtime?

Sep 15, 2009

Is there a way to dynamically create properties at runtime in VB .NET using introspection?

e.g. Suppose I had a class

Public Class Foo
Public Property Bar() As String
get
...
end get

[code]....

Is there a way to create property Bar at runtime?

View 4 Replies

Dynamic Runtime Library Linking?

Aug 4, 2010

I have a .NET library which I know can be fairly easily linked from VS project to reference it from code. However for security reasons I want to place the DLL file in another location on the disk and reference it from code including executing methods and passing method parameters. What is the proper technique to accomplish this?

View 4 Replies

Dynamic Variable Naming At Runtime?

Oct 30, 2009

I am trying to create a number of objects depending on the width of a row of an array, is there a way I can change the name of the variable being Dim 'd as I don't know how wide the array will be.

I have been trying something along the lines of:

pseudocode
For x as integer = 0 to UBound(MyArray,2)
Dim Object & CStr(x) As Object Type
Next

View 3 Replies

Winforms - Dynamically Adding Event Handlers To Dynamic Panels?

Mar 31, 2012

so i have a series of panels that are generated

example:

For i as integer 1 to dt.rows.count
dim subpan as new panel
*Code for creating panel"
Next

the problem is i need to be able to add event handlers to each of them including, click, mouseEnter and mouseLeave but i can't figure out how to index each panel so that they can be accessed and identified. i tried using a property but that didn't seem to work or i was doing it wrong.

View 2 Replies

.net - Dynamic Linq Query?

Mar 14, 2011

I have been trying the following but it returns unexpected results:

Dim xd As XDocument = _
<?xml version="1.0" encoding="utf-8"?>
<root>

[code].....

The above result returns both 'element' nodes however it should only return the first where element/subelement@id=1/subsubelement@id=3 However if results.Ancestors. is used it returns the correct 'subelement' and if that line is not included it returns a single 'subsubelement' whih is also correct I don't understand why when mvoing to the 'element' it returns both (I realise both have a subelement with id=1 but I thought each further query would filter out the presvious results)?

View 1 Replies

C# - Abstracting Dynamic Linq To SQL Where

Feb 24, 2012

UPDATE: Groo's answer was marked correct as it would be a good alternative. I decided to stick with the select/switch statements to avoid the performance issues of using reflection. As far as I can tell there is no way to do what I want without using Dynamic LINQ (and reflection) or a decompiler (to manually code each LINQ statement, which I am already doing by hand). Note: to make this update DropDownList16 through DropDownList20 were removed (needed the characters).Is there a way to abstract the building of a dynamic Linq to SQL query?

I am trying to build a Linq to SQL query with a dynamic where clause, based on user supplied filters. The user needs to be able to filter strings, integers, and dates using advanced options (equal, not equal, contains, starts with, etc). The user needs to be able to use these filters with as many or few columns as desired.

[Code]...

View 2 Replies

Dynamic Column In Linq?

Jan 5, 2010

Dim query=Form f in BBSDb.Forms order by f.FormID Descending Select f where I want the f.FormID to be able to replace with a variable..What I mean is.. it doesn't have to f.FormID .. I may want to set f.FormName to be in descending for example using the code dynamically.. Is there anyway to achive?

View 2 Replies

Dynamic Query Linq To Xml?

Mar 16, 2011

I want to write a query that the "where" in the query is a string something like"

Dim query as string= "Name =xxxx and Date > 10 "
Dim t = from book in doc.Descendants("books") Select _
[Name] = book..value, [Date] = book..value....
Where (query)

I build the query string on run time

View 2 Replies

Using Dynamic LINQ In Vb 2008?

Oct 17, 2011

This is an extension of my last question which was answered, so I am starting a new thread. I have a query in LINQ that I was given to trim down the columns of a datatable. This works well, however, I need to make the LINQ query dynamic. So the query below:

Dim qColumnsIWant = From row As DataRow In inDT.AsEnumerable() _
Select _
EPN = row.Field(Of Integer)("EPNID"), _
EPNID = row.Field(Of String)("EPNNumber"), _
Ingot = row.Field(Of String)("Ingot"), _
ShopOrder = row.Field(Of String)("ShopOrder")

View 5 Replies

Add Dynamically Controls In Runtime In The Form?

Nov 19, 2010

I'm wondering, when I add dynamically controls in runtime in the form - is there a way to save this controls, and they appear the next time when you run the application?

I'm using VB9.

View 2 Replies

Create EXEs At Dynamically At Runtime?

Dec 31, 2011

A while back I asked a question on how to create EXEs at dynamically at runtime. This time, I wanted to know how to add code to your program dynamically at runtime too. Like if I had a textbox on a form, and I typed whatever code into it, then it would add the code to a subroutine and it would be executed. How can this be done?

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved