.net - Linq To SQL With Multiple Unions?
Oct 29, 2010
I have a linq union statement that has been giving me some trouble and I can't see where the issue is.The error is....All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.
I know the error means that I am selecting different amounts of elements in one of the linq statements, but I've examined this query extensively and I haven't been able to see that as the issue.
[Code]...
View 1 Replies
ADVERTISEMENT
Jul 22, 2009
That is the question. Is there anything you can do with c++ unions that you can't with c# Explicit structs?
View 3 Replies
Jul 22, 2009
I am running into a problem which I am using C Dll into my VB.net code. I have .H file which shows implementation of this DLL in C language.This .H file contains many structures and unions that contain variable of some structures type. There is a main structure which contains the pointers to these structures and unions and finally address of main structure is passed into the dll function.
I am enable to figure out how to create structures and unions with marshalling in vb.net and how to pass address of a structure which contains addresses of othere structures and unions.
View 2 Replies
Mar 4, 2012
I am trying to pass several search parameters to an LINQ expression to retrieve all entries that contain one of the search items.
Example:
Dim query = From p In db.BEW_PROFIL
For Each searchItem As String In searchItems
[code].....
View 2 Replies
Jul 8, 2010
How would I perform this SQL query
Select Distinct s.*
from #ScopeIDs x
Join Scopes s on s.ScopeID=x.ScopeID or x.ScopeID is null
in LINQ to SQL? (This query would return all Scopes whose ScopeID is present in #ScopeIDs, unless one of the entries in #ScopeIDs is null, in which case it returns all Scopes).
A "literal" translation doesn't work, since LINQ doesn't support joining with multiple conditions - code along these lines ...
From x in ScopeIDs
Join s in Scopes on s.ScopeID equals x.ScopeID or x.ScopeID equals nothing
Distinct Select s
... doesn't compile.
View 1 Replies
Dec 6, 2011
I have a list of attachments that I need to group by clientCLID and EmailAddress. From this grouped list I only need a list of clientCLIDs. After fiddling for a while I've managed to get it to work as follows:
[Code]...
View 1 Replies
Jun 10, 2011
I spent a lot of time on this problem. I am able to do simple Group By LINQ queries (on one property) but for multiple fields I'm a little stuck... Here is a LINQPad sample of what I want to do :
dim lFinal={new with {.Year=2010, .Month=6, .Value1=0, .Value2=0},
new with {.Year=2010, .Month=6, .Value1=2, .Value2=1},
new with {.Year=2010, .Month=7, .Value1=3, .Value2=4},
[Code]....
View 3 Replies
Mar 20, 2011
in my prev question i was suggested with LINQ solution. It was great and simple. I tried to solve next similar but a bit diff problem with similar approach but i failed.
how can i make the below code better
For Each Item As ListViewItem In RoomsListView.Items
For Each Item1 As Room In myBookedRooms
If Item1.UIN = Item.SubItems(1).Text Then
[Code]....
View 2 Replies
Sep 11, 2010
it is possible to do a multiple records editing by linqtosql method in one click event?What I've been trying to do is to edit all the names in the table which are having the same account number.
Private Sub Button2_Click(------------) Handles Button2.Click
Dim accnt As String
accnt = Textbox1.Text
Dim db As New memrecDataContext()
[code]....
Why is it these codes could only edit records in one datarow?Can you debug the codes to edit all records which are having the same account number after it is being query?
View 5 Replies
May 11, 2012
I'm using Entity Framework code first and pulling some data back from our database. In the table I'm accessing is 13 columns that store the number of a items a customer purchased per week for the last 13 weeks as a char field. I have no control over how this data is stored. I need to total the 13 weeks results together to get a combined total, so take week1 + week2 + week3.... = Total Items Purchased over 13 weeks.In SQL I'd just Cast the char to an Integer and add the values together. But I'm struggling finding a solution to do this in linq.
I tried
(From c in Table
Select New With {.Usage = (Convert.ToInt32(c.week1) +
[code]......
View 1 Replies
Aug 8, 2010
I call upon the VB ninjas out there. Here's my situation. I need to eventually be able to pass multiple models to a view. Currently I have a linq to sql class that, of course, has a bunch of generated model definitions. I need to make a model that implements multiple models. I somewhat understand how to do this in C#, but this project is testing my VB skillz. Here's some snippets from my linq to sql models. I need to combine these two into one model to pass to the view.
[Code]...
View 1 Replies
Jun 7, 2012
On my view there is a datatable holding a collection of ServerRow and 4 textboxes (Hostname, OS, Location, Zone). When the user types into any of the 4 boxes I want to immediately filter this list. I have this code setup and ready to go that on the set method of each textbox property I call the filter method.
Now onto the problem: if I have 4 criteria that means I have 2 to the power of 4 different scenarios. What I would like to do is write a linq statement with all of these scenarios dealt with such that if any of the properties are NullOrEmpty they will not be used in the Where clause and on the flip side if there is a value the corresponding field will be searched with a Contains.
Example
AvailableCis = New ObservableCollection(Of ServerRow)
(_CiData.Where(Function(ci) ci.OS.ToUpper
.Equals(_selectedOS.ToUpper) AndAlso
ci.HostName.ToUpper.Contains(_ciNameFilterText.ToUpper))
.OrderBy(Function(a) a.CiName))
This example shows how it works with 2 criteria and both of those criteria are set.
View 1 Replies
Sep 23, 2011
I have the following example datatable:[code]And now the user should be able to compare multiple periods. In this example the user chose two periods: 1.1.2010 - 31.12.2010 and 1.1.2011 - 31.12.2011. The result of the example should be:[code]
View 2 Replies
Feb 8, 2012
I have been searching for quite a while about joining multiple datatables via LINQ to dataset (When i say multiple, i don't mean just 2!!!), and it seems there aren't lot of examples in the net. I have seen examples of joining two datatables, done that, no problem there. Now i want to join three datatables. And there's nothing i can find out there.For example i have a 3 datatables:
PERSON (columns: person_id, name, gender_code, ethnic_code)
GENDER (columns: gender_code, gender_description)
ETHNICITY (cols: ethnic_code, ethnic_description)
[code].....
View 1 Replies
Mar 24, 2012
I have a Table:
[Code]...
I'm trying by LINQ-query (VB.NET) to return a count for distinct value of Objects, Stuffs and Colours for every Room:
[Code]...
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
Apr 3, 2012
I am stumped. I have a DTO object with duplicates patient address data. I need to get only the unique addresses.
[Code]...
View 3 Replies
Aug 9, 2010
I have the following table structure. I want to select distinct CustomerId and CustomerName, TotalCost.[code]
View 2 Replies
Apr 2, 2010
I'm using LINQ to SQL to select some columns from one table. I want to get rid of the duplicate result also.
Dim customer = (From cus In db.Customers Select cus.CustomerId, cus.CustomerName).Distinct
Result:
1 David
2 James
1 David
3 Smith
2 James
5 Joe
Wanted result:
1 David
2 James
3 Smith
5 Joe
Can anyone show me how to get the wanted result?
View 3 Replies
Mar 10, 2010
I have to forms, form1 and form 2. On form1 I have datagridview with all the fields in it. If I double click on it I would like a new form to open where I can add a new record.
Then I have a edit button on the form, If I click the edit button I would like another form to open where I can edit the data in.
In this post it explains it, I need the same but for linq to sql.
[URL]
View 4 Replies
Mar 17, 2010
I'm in the process of moving from ADO.NET to Linq. The application is a directory search program to look people up. The users are allowed to type the search criteria into a single textbox. They can separate each term with a space, or wrap a phrase in quotes such as "park place" to indicate that it is one term.
Behind the scenes the data comes from a XML file that has about 90,000 records in it and is about 65 megs. I load the data into a DataTable and then use the .Select method with a SQL query to perform the searches. The query I pass is built from the search terms the user passed. I split the string from the textbox into an array using a regular expression that will split everything into a separate element that has a space in it. However if there are quotes around a phrase, that becomes it's own element in the array. I then end up with a single dimension array with x number of elements, which I iterate over to build a long query.
I then build the search expression below:
query = query & _
"((userid LIKE '" & tempstr & "%') OR " & _
"(nickname LIKE '" & tempstr & "%') OR " & _
[Code]....
View 1 Replies
Oct 19, 2009
I would like to ask if it is possible to do a multiple records editing by linqtosql method in one click event? What I've been trying to do is to edit all the names in the table which are having the same account number. I was able to edit but only one name has been edited and the rest are not
******************************************************
Private Sub Button2_Click(------------) Handles Button2.Click
Dim accnt As String
accnt = Textbox1.Text
[Code]....
Why is it these codes could only edit records in one datarow? Can you debug the codes to edit all records which are having the same account number after it is being query?if that is possible for you.
View 3 Replies
Feb 17, 2012
I have a program that is accessing many similar tables using a linq to sql datacontext. Do linq to sql tables implement a common interface? I would like to write methods that could work with any of the similar tables, so it would be great to do something like
Dim myTable as ILinqDataTable
If switch = "TableA" then myTable=myDataContext.TableA Else myTable=myDataContext.TableB
[Code]...
View 1 Replies
Jul 11, 2011
I have an EnumerableRowCollection that looks like the following:
VendorCode | GroupType | Variance
01165 G .16
01165 G .16
01165 CH .16
01165 CH .18
07754 G .25
07754 G .25
07754 G .39
Essentially, this is a massive list of vendor codes, their groups, and price variances. I need to compose a query that will create a distinct list vendor codes and group types. The catch, however, is that I need to evaluate all of the variances associated with that particular VendorCode/GroupType to see if they are all the same - it they are not, I need to return some way of signifying that the group has a "custom" variance, otherwise it needs to return the value (ie: if they are all .16, then return .16, if there are multiple values, return "custom")
The result would look like this, based off of the list I showed above.
VendorCode | GroupType | Variance
01165 G .16
01165 CH custom
07754 G custom
I have no trouble getting a distinct list of VendorCode/GroupType - this is what I have so far:
Dim distinctList = From q In query Select q.VendorCode, q.GroupType, (evaluated q.Variance here?) Distinct
(where "query" is an EnumerableRowCollection(Of (anonymous type)))
I'm at a loss, though, on how to evaluate the variance property to get the result that I need?
View 1 Replies
Aug 19, 2010
I have three tables Student, TimeSheet and TimeRecord.
Talbe columns:
Student : StudentId, FirstName,
LastName
TimeSheet: TimeSheetId,StudentId, IsActive
[Code].....
View 4 Replies
Oct 19, 2009
Is it possible to do a multiple records editing by linqtosql method in one click event? What I've been trying to do is to edit all the names in the table which are having the same account number. I was able to edit but only one name has been edited and the rest are not.
The codes I used.
Private Sub Button2_Click(------------) Handles Button2.Click
Dim accnt As String
accnt = Textbox1.Text
Dim db As New memrecDataContext()
Dim editrecord = From mem In db.Table1s
[Code] ......
Why is it these codes could only edit records in one datarow?
View 1 Replies
Mar 7, 2011
Can anyone help me by translating this SQL Statement to Linq? [code]
View 1 Replies
Dec 7, 2010
I have a VB .Net linq query that I want to return values from two tables. I currently have this:
Dim query = (From c In db.Client _
Join u In db.Users _
On u.UserID Equals c.UserID _
Where (c.ClientID = 1)
Select c, u).ToList
query (System.Collections.Generic.List(Of )) returns several rows as expected each item containing a c and a u.
How do I iterate through the queries collection?
View 1 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
Apr 16, 2010
basically i'm trying to reproduce the following mssql query as LINQ
SELECT DISTINCT [TABLENAME], [COLUMNNAME] FROM [DATATABLE]
the closest i've got is
Dim query = (From row As DataRow In ds.Tables("DATATABLE").Rows _
Select row("COLUMNNAME") ,row("TABLENAME").Distinct
when i do the above i get the error
Range variable name can be inferred only from a simple or qualified name with no arguments.
i was sort of expecting it to return a collection that i could then iterate through and perform actions for each entry. maybe a datarow collection?
As a complete LINQ newb, i'm not sure what i'm missing.
i've tried variations on
Select new with { row("COLUMNNAME") ,row("TABLENAME")}
and get:
Anonymous type member name can be inferred only from a simple or qualified name with no arguments.
to get around this i've tried
Dim query = From r In ds.Tables("DATATABLE").AsEnumerable _
Select New String(1) {r("TABLENAME"), r("COLUMNNAME")} Distinct
however it doesn't seem to be doing the distinct thing properly.
View 3 Replies