Linq Using Variables In Order By Statement?
May 18, 2012
Dim gg = From gs In AllData_TableList Order By gs.Biology Descending, gs.ChemistryDescending, gs.English Descending, gs.Frensh DescendingAll I need is to make this Statement order Dynamically like this
Dim Variable1 as string=Biology
Dim Variable2 as string=Chemistry
Dim Variable3 as string=English
[code].....
View 6 Replies
ADVERTISEMENT
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
Jun 24, 2011
I have the following SQL:
[Code]...
I want to put it (the select count statement) in this LINQ statement so I can get the sales count in my linq statement: Dim TheLeads = (From L In DB.Leads Where L.IsDeleted = False Select L).ToList() Is this possible to do in LINQ?
View 1 Replies
Jan 27, 2011
We are doing a query against an in-memory collection of LINQ data objects. The wrinkle is that we are ordering by a column in a related table whose records have not necessarily been loaded yet (deferred loading:)
Dim oPkgProducts = _
From b In oBillPkg.BillProducts _
Where b.Successful.GetValueOrDefault(Common.X_INDETERMINATE) = _
[code]....
View 1 Replies
Feb 22, 2009
[code]...
where and how do I implement the if statements and zorder statments for each form. If btncustomerservice_click = true then Form2.Zorder1 Form2.Show ElseIf btncustomerservice_click = false then form2.Zorder2 End If I believe I need these statements to avoid any other possible exception or error messages. These statements worked in vb6. How do I do this in vb 2008. Do I need to? What else can I do.
View 3 Replies
Jul 26, 2010
I am trying to make 2 variables available throughout my site. I am parsing the URL in order to retreive both of them. This code on the page itself works fine.
[Code]...
View 3 Replies
Aug 20, 2009
Which is a better practice? (I'm coding in .Net if that makes a difference)
IF condition = true THEN
...true action--even if rare...
ELSE
[code].....
View 10 Replies
Aug 8, 2011
Using VB.net and the following LINQ statement. I suspect the "Order by" does not work with Concat(). I want to list the current item the user has and then list more available items in asending order. So first i select the current item from the db and then select the next available items in order. LINQ is ignoring the order by statement and sorting by the PK (which is itemID) I examined the list immediately after executing the statement. When I break up the statement and do them separately they work as predicted.
(From items In myDatabase.ItemAssignments _
Where items.BuildingID = buildingID _
And items.ResidentID = ResidentID _
[Code].....
View 1 Replies
Sep 21, 2010
Same thing I am trying to do in the linq order by. It's not working.I have column that is defined in the data base as string (Varchar) and I need to cast/convert it to integer before I need to sort it.What should be my linq statement?
View 1 Replies
Mar 14, 2012
I have a Dictinary(Of String, Item) and I'm trying to sort it into alphabetical order by the item name. I don't want to use a sorted dictinary and without it, I've having zero luck. Linq is not my strong point.
[Code]...
View 2 Replies
Mar 3, 2009
How do I order by a passed string value on my list of objects? i need to do paging and sorting on my List(Of) objects the paging is no problem but I don;t know who to get the Order By to work.Here is what I am currently doing and it's working great:[code]
View 4 Replies
Mar 30, 2011
I have a LINQ Query:
[Code]...
This works great and sorts on L_Name. But I am trying to allow the user to sort the gridview themselves so I am passing in the SortExpression as a string. But I don't know how to incorperate the SortExpression into the LINQ Query. I tried Order By c. & SortExpression but that did not work.
View 2 Replies
Feb 7, 2012
I have following code that creates Linq query.
I've never used Linq until today and having problem with "Order By Clause"[code..]
If I run the code, I get following error.Name 'p' is either not declared or not in the current scope. How come p!Weight in "Select Clause" works but not in "Order By Clause"?
View 1 Replies
Apr 16, 2010
[code]How do I use variables in a SQL statement?
View 20 Replies
Jan 31, 2012
I wonder how to use statement handles exceptions?Do I need to wrap the using statements with a Try/Cath/Finally clause in order to be sure that the SqlConnection object is closed and disposed even if the containing code throws an exception? [code]
View 3 Replies
Apr 12, 2012
I've a structure collection like this:
Jet Owner Item Comp
AAAA AAAA 101 2210
AAAA AAAA 202 2220
[code].....
View 1 Replies
Mar 19, 2010
I am using a modal form with a datagridview in order to populate textboxes on a parent form. The datagridview is bound to an anonymous type resulting from a linq query, which varies depending on the textbox control whose keypress event is called. I always want to display a key value in column 0 of the datagridview (along with a variable number of additional columns), and then use that key value once the user selects a row.
However, when setting an anonymous type from a linq query as the datasource for a datagridview control, the columns are indexed alphabetically rather than in the sequence selected in the query. This requires setting the displayindex as a workaround, and then keeping track of which column contains my key value. I read elsewhere that this was something fixed in VS2008 SP1, but I still encounter the behavior.
View 1 Replies
Mar 15, 2012
I have collections of 2 different types - let's call them Cars and Trucks. Both share base class Vehicle, which has property Passengers.I want to merge them into a single collection ordered by that property. E.g., merge Cars and Trucks and order by Passengers.
View 2 Replies
Jan 5, 2012
I am using linq to fill a gridview with the information from an xml from code behind. I would like to order my Grid according to one of my elements in the xml ("value element").
gvResourceEditor.DataSource = (From resElem In resourceElements.Elements("data") _
Select New With { _
.Key = resElem.Attribute("name").Value, _
.Value = HttpUtility.HtmlEncode(resElem.Element("value").Value), _
.Comment = If(resElem.Element("comment") IsNot Nothing, HttpUtility.HtmlEncode(resElem.Element("comment").Value), String.Empty) _
}).OrderBy(?????)
View 1 Replies
Jan 16, 2012
I have the following:
myFilteredContractors = (From c In myFilteredContractors
Join cc In myConClasses On c.ContractorId Equals cc.ContractorId
Where inClassifications.Contains(cc.ClassificationId)[code].....
This is properly ordering this list of contractors by the number of classifications that they have.I also want to order them by whether or not they have a field set (CompanyOverview), which if is an empty string should be below those contractors who have set their CompanyOverview. Also, after the CompanyOverview is ordered I want to order by Registration Date.So it should order by:
Number of Classifications
Whether Overview has been set (c.CompanyOverview)
Registration Date (c.AppliedDate)
Is it possible to all of this in LINQ?
View 1 Replies
Sep 28, 2010
How do I order by and group by in a Linq query?I tried..Dim iPerson = From lqPersons In objPersons Where Len(lqPersons.Person) > 0 Group lqPersons By key = lqPersons.Name Into Group Order By Group descending Select Group, key
For Each i In iPerson
tmp = tmp & vbNewLine & i.key & ", " & i.Group.Count
Next
[code].....
View 5 Replies
May 25, 2011
I have a LINQ to sql statement that joins 2 tables. I would like to add a order by clause on one of the columns. However the order by clause does not seem to take effect at all. right syntax in VB.net to achieve order by in the following:
Dim query = From dtIt In dbsomecontext.mytable
Join dtIl In dbsomecontext.anothertable On dtIt.ItemID Equals dtIl.ItemID
Where dtIl.IsAvailable = True
Order By dtIt.manufacturer
[Code]...
View 2 Replies
Jun 14, 2011
Suppose I have the following data
Key ID Data
A 1 Hello
A 2 World
B 2 Bar
B 1 Foo
I am looking to produce the result
A HelloWorld
B FooBar
I am struggling to get the syntax quite right - I was trying to use Aggregate, but I wasn't sure if I could (or should) use SelectMany
Dim data = result.Rows.
GroupBy(Function(r) r.Key).
Select(Function(g) g.OrderBy(Function(s) s.ID)).
[Code]....
View 4 Replies
Aug 20, 2010
I have a simple table in an access database that I'm using in a VS2010 project. I have a combobox control that a user can select the horse power of a motor. I then take that selected value from the control and copy it to a string variable called gstrSelectedHP. All I want to do is run a query that will pull up the full load amps of that horse power motor from the table. I have the query already, but I need to somehow put the gstrSelectedHP in the WHERE part of the query so that it only returns that value.
View 14 Replies
Apr 16, 2010
I got this in my SQL statement. I "BOLDED" the problem.SELECT OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia, Freight, ShipName, ShipAddressShipCity, ShipRegion, ShipPostalCode, ShipCountry FROM Orders WHERE CustomerID =@CustomerID
View 5 Replies
Apr 16, 2010
I got this in my SQL statement. I "BOLDED" the problem.
SELECT OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry FROM Orders
[code]......
View 2 Replies
Nov 16, 2009
I'm still trying to get my head around the whole "Lambda Expressions" thing.
Can anyone here give me an example ordering by multiple columns using VB.Net and Linq-to-SQL using a lambda expression?
Here is my existing code, which returns an ordered list using a single-column to order the results:
Return _dbContext.WebCategories.OrderBy(Function(c As WebCategory) c.DisplayOrder).ToList
Note: The WebCategory object has a child WebPage object (based on a foreign key). I'd like to order by WebPage.DisplayOrder first, then by WebCategory.DisplayOrder.
I tried chaining the order bys, like below, and though it compiled and ran, it didn't seem to return the data in the order I wanted.
Return _dbContext.WebCategories.OrderBy(Function(c As WebCategory) c.DisplayOrder).OrderBy(Function(c As WebCategory) c.WebPage.DisplayOrder).ToList
View 2 Replies
Sep 9, 2010
I am using LINQ queries inside a WCF service to return data to a Silverlight frontend. Problem is the columns being returned using LINQ are in alphabetical order and I want them the way they are ordered in the database instead. Does anyone know how to stop the alphabetical ordering of column names?
View 4 Replies
Apr 11, 2011
with the following code example:
T04Command04 = New SqlCeCommand("Update GameResults Set CN01=@T04Var02 Where Counter=@T04Var03", T04Database01)
T04Command04.Parameters.AddWithValue("@T04Var02", T04N01)
T04Command03.Parameters.Add("@T04Var03", T04ClnRec01)
T04Command04.ExecuteNonQuery()
I am trying to use two different variables in this SqlCeCommand series, to (1) update only a particular record in the database (2) with a particular variable value. However, I get the following error:
"An SqlCeParameter with ParameterName 't04var03' is not contained by this SqlCeParameterCollection."
View 2 Replies
Jan 26, 2012
I get the following string expression provided:"ChildObject.FullName" ...where ChildObject is an instance property on the MyObject1 type.ChildObject has a property named "FullName" and I want to sort a collection of type "MyObject1" based on this child properties "FullName" value.
I can do this all day long on properties directly on MyObject1 but I run into 2 challanges when doing it on a child instance and I can't get all the pieces working. The main 2 challanges are:
MyObject1 has a few different child property types so I can't hardcode the type for ChildObject. The string could be of any type.The sort expression is a String and not a known type.Above the value returned from the last line in the expression (if I run the code outsode the OrderBy method, does provide me the 'FullName' information I need. So the code must be close, but it still does not work.
Any ideas on how I can accomplish this? What I am trying to prevent is hardcoding a series of 'If' blocks on the child's type to then hardcode in its type to the sort or OrderBy method.
View 2 Replies