VS 2010 LINQ To XML Customizable WHERE Clause?

Jun 13, 2012

So I have a query I'm doign where, at the moment, the places to search are set in stone, but the values that maybe be searched for is variable.Right now, I have a drop down menu that allows you to choose a character class. This limits the items to a specific class. Then I can filter on text from a textbox.

However, each item in the list has a source, based on the book it is published in. I want a user to be able to choose several from a checkbox menu, then pass those values for inclusion in the criteria for finding items.

The problem I'm having is finding the most concise way to do dynamic WHERE clauses. There are several examples out there, and even a couple don't seem to want to do exactly what I'm doing, and I'm having trouble determining if it will work for me.

View 8 Replies


ADVERTISEMENT

VS 2010 - Saving Own Customizable Spamming Options

Jul 27, 2011

I was trying to code a save option for my project, it's a spammer that I have created and I have made it to where people can have their own personal spam message and when they want to use it all they have to do is click a radio button and the text will appear in the text box. Now like I said I want it to save, like they make their own customizable spamming options and then save it so they want have to continue typing in the message because that would defeat the purpose of my project.

Here is the code:
TextBox2.Text = (TextBox2.Text)
RadioButton1.Text = (TextBox2.Text)
TextBox3.Text = (TextBox3.Text)
RadioButton2.Text = (TextBox3.Text)
TextBox4.Text = (TextBox4.Text)
[Code] .....

Though it wouldn't work unless I imputed this code
Private Sub SaveSetting(ByVal p1 As String)
Throw New NotImplementedException
But when I start the program it quits and says the " NotImplementedException" is unhandled:/

View 1 Replies

.Net Linq - How To Append A Where Clause

Apr 23, 2009

Pretty new to VB.Net. Having a bit of trouble here with something I though should be simple.Keeping it simple. Let's say i have a Document table with "Name" that I want to search on (in reality there are several other tables, joins, etc ..). I need to be able to build the query where clause based on string values passed in.

Example - user may pass in "ABC" or "ABC DEF" or "ABC DEF GHI".The final query would be (syntax not correct i know)Select * from Documents Where Name Like %ABC% AND Name Like %DEF% AND Name like %GHI%

So, I though I could do something like this.


Dim query = From document In _context.Documents
<< loop based on number of strings passed in >>
query = query.Where( ... what goes here?? )

For some reason, being brain dead or something, I can't figure out how to make this work in VB.Net, or if I'm doing it correctly.

View 5 Replies

Where Clause On This LINQ Query

Nov 25, 2009

Dim dataContext As New ACSLostFoundEntities()

Dim query = From s In dataContext.FosterForms() _
Join c In dataContext.Fosters() _
On c.License Equals s.License _[code]....

At the end of this I want to do a Where WantedPets.Contains(criteria), is this possible?

View 1 Replies

Asp.net - Make A Dynamic Where Clause: Linq To Sql?

Jun 28, 2011

I have the following linq query:

Dim q = From definition In definitionList _
Where definition.ValueDefName.Contains(criteria)[code]....

I have already looked into this answer: LINQ - dynamic WHERE clause?Unfortunately, it doesn't work for me using .net 4.0. When I attempt to pass the criteria string in it ask for a predicate. The end goal is to add any of these:

definition.ValueDefname.Contains(criteria)
definition.ValueDefDesc.Contains(criteria)
definition.Aliaslist.Contains(Criteria)
definition.StrategicInitiative.Contains(Criteria)

to be passed into the query depending on what checkboxes the user has selected. How can I create a dynamic where clause in linq to sql? Is there new syntax for passing in a where clause as a string?

View 2 Replies

C# - Linq Query With Dynamic Where Clause?

Apr 13, 2012

I'm need to do the equivalent of a t-sql statement like this using LINQ:

SELECT * FROM mytable WHERE idnumber IN('1', '2', '3')

so in LINQ I have:

Dim _Values as String = "1, 2, 3"
Dim _Query = (From m In mytable Where idnumber = _Values Select m).ToList()

Not sure what to do with _Values to make idnumber evaluate each value in the string.

View 2 Replies

Iif Condition In Linq Query Where Clause

Aug 25, 2011

Whats wrong with the below query, I am getting this error: Nullable object must have a value.

[Code]...

View 3 Replies

Linq To DataSet Order By Clause

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

LINQ To SQL And Join Two Tables With OR Clause

Apr 23, 2009

Let's say I have Plans and Documents
Dim myPlans = _context.Plans.Where(predicate1)
Dim myDocuments = _context.Documents.Where(predicate2)

I have structured the where clause for each using PredicateBuilder. So, myPlans and myDocuments have a correct SQL statement. What I'd like to do is join these two tables into one linq statement. The problem I'm having is that, by default the AND condition is joining the where clauses.

myPlans Where clause : (p.name like "%test%" AND p.name like "%bed%") OR (p.description like "%test%" AND p.description like "%bed%")
myDocuments Where clause : (d.name like "%test%" AND d.name like "%bed%") OR (d.description like "%test%" AND d.description like "%bed%")

When I combine the two the desired result Where clause is:
Where (d.ID = p.ID) AND
(myplans where clause above) OR (mydocument where clause above). Meaning, I'd like the two where clauses in each of the tables to be "or" instead of "And".

The current result where clause is:
Where (d.ID = p.ID) AND
(myplans where clause above) AND (mydocument where clause above). Meaning, I'd like the two where clauses in each of the tables to be "or" instead of "And".

I'm forming the statement like this:
Dim test = From d in myDocuments _
Join p in MyPlans on d.ID Equals p.ID _
Select d.Name, p.Name

View 2 Replies

VB Dataset Linq With String Where Clause?

Mar 17, 2009

Right now our queries can be driven through the DataTable Select statement. However, utimately we want to end up with more complex queries. We think Linq is the answer, but can't find anyexamples of this.Here is the sysnopsis:I have a dataset containingdatatable(s) of informationI have a datatable containing business rules as strings like:

(ISNULL(MEMLNAME, '') = '')
(#1880/01/01# <= CONVERT(BIRTHDATE, 'System.DateTime') AND CONVERT(BIRTHDATE, 'System.DateTime') <= #2009/12/31#)

[code].....

View 3 Replies

.net - Reset Index In LINQ Select Clause?

Mar 13, 2012

My LINQ query:

Dim groupedData = (From p In pData _
Group By p.TruncParam Into Group) _
.SelectMany(Function(g) g.Group) _
.Select(Function(d, idx) New With { _

[Code]...

When the TruncParam changes, I would like the index (idx) in the Select clause to reset to 1. So, in the list above, the Index should be SOLUB0001, SOLUB0002, INSOL0001, INSOL0002...CLRES0001, SUMCA0001, SUME0001.

How should I alter the LINQ query?

View 1 Replies

Asp.net - Linq Where Clause Not Producing Expected Results

Nov 8, 2011

I have the following xml:

<Root>
<Result img="1.png" name="a">
<Programs>

[Code].....

What is wrong with linq query. Why does a 1 work but a 2 does not? I would also like xml structure preserved after filtering.

View 1 Replies

Can't Use A Where Clause On Both Tables In A LINQ Group Join?

Jun 7, 2011

Here's what I want to do:

Dim queryX = From m In db.Master
Where m.Field = value
Group Join d In db.Detail
On m.Id Equals d.MasterId Into Group
Where d.Field = value

In English, I want to join the master and detail tables, specifying conditions on each. But this causes the following compiler error:

"Name 'd' is either not declared or not in the current scope."

It works if I put this same condition in functional form:

Group Join d In db.Detail.Where(Function(x) x.Field = value)

but I think this is more typing, harder to understand, and introduces that irritating dummy variable. I really would prefer to use the query comprehension syntax. Is there a way to accomplish this?

View 1 Replies

Compare Nullable Types In WHERE Clause Of Linq To Sql .NET?

May 4, 2012

I am trying to query for records where that column IS NULL:

Dim UnassignedSubSvc =
From c In CurrentContext.SubService
Where c.Product.ProductSubServiceId **is null**
Select c).ToList()

View 1 Replies

Syntax For Order By Clause In Linq To Sql That Has Select New With

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

VS 2008 IfThen Statement In Linq To Sql Where Clause?

Aug 19, 2010

i want to use a if, then statement in a where clause in linq to sql. Is this possible? I'm trying to achieve the following:

[Code]...

I'm trying to only add the And If if intLink_pk > -1. If it = -1, then i don't want the and clause at all. Is this posssible within the linq to sql itself?I understand i can write 2 entirely different selects, but if I can't get this done, I may have to write about 50 of them as I want to use multiple Ands if certain conditions are met on the form, such as chk boxes etc.

View 3 Replies

.net - Substitute Field Name In Linq Where Clause By Combo Text?

Jun 22, 2012

I have a combo with 6 text NA,PO,FA,GO,VG,EX and I want to do a Linq query upon the selected value in this combo used as field in the where clause. for example:

'if "NA" is selected :
Dim query = from t in db.table where t.NA > 0 Select t
'If "PO" is selected :
Dim query = from t in db.table where t.PO > 0 select t

How to do this in elegant way without writing 6 if statement or using "Select case"

View 1 Replies

.net - Linq-to-Entities: LEFT OUTER JOIN With WHERE Clause And Projection?

Oct 18, 2010

how to translate a simple SQL LEFT OUTER JOIN with a two condition where clause into a working Linq-to-Entities query. There are only two tables. I need values for all rows from Table1, regardless of matches in Table2, but the WHERE clause uses fields from Table2. In SQL, the two parameters would be Table2WhereColumn1 and Table2WhereColumn2, and the query (which works) looks like this:

SELECT t1.Table1Id,
t1.FieldDescription,
t2.FieldValue

[code].....

I've tried using Group Join with DefaultIfEmpty(), as well as an implicit join (without the actual Join keyword), and I only get rows for items that have values in Table2. I'm sure this won't help, but here's an example of the Linq I've been trying that doesn't work:

Public Shared Function GetProfilePreferencesForCedent(ByVal dc As EntityContext, _
ByVal where1 As Int32, _
ByVal where2 As Int32) _

[code].....

View 1 Replies

VS 2010 Upgrade From 2008 To 2010 - Now LINQ - IntelliSense Is Not Working For LINQ Stuff

Apr 20, 2010

I just upgraded a project from VB 2008 to VB 2010. Before, the project did not use LINQ. I have started implementing it. So, I have updated the target framework from 2.0 to 3.5, and added a reference to System.Core, and imported the namespace System.LINQ to the entire project and also imported System.Data.LINQ into the form I'm working with (because it was not available in the list for Imported Namespaces in the references tab).

It's not throwing any errors now, but my IntelliSense is not working for LINQ stuff.

For example... I write this:

[CODE]....................

Then, if I type S. on the next line, the IntelliSense doesn't grab what it should for S (Only get Equals, GetHashCode, GetType, ReferenceEquals, and ToString, instead of the options I should get like Count, First, FirstOrDefault, etc...). If I Type S.First. then its the same thing, no IntelliSense that lists the available fields for S, just the standard options (Equals, GetHashCode, GetType, ReferenceEquals, and ToString). I should be seeing my column names in my table when I type S.FirstOrDefault.

So any ideas what is going on? When I type the code, for example, MessageBox.Show(S.FirstOrDefault.FirstName), it works perfectly. But it doesn't change the casing of the text (so it would read s.firstordefault.firstname) and no intellisense while doing it. But no errors. BTW - Everything works perfectly when creating a NEW VS 2010 application, it's just my projects upgraded from Visual Basic 2008 that have this issue.

View 2 Replies

Highly Customizable Listview For .Net?

Mar 20, 2011

do you guys know a .net ListView-Replacement which can be highly customized?I am developing an app which is similar to a "todo" list.I want to be able to customize almost every visual detail of the list so I get something like this: I want also to be able to reorder items by mouse + I need drag&drop.If you don't know any ListView, maybe you know how I could make my own listview like this one from scratch?

View 3 Replies

.net - Search The Collection Of A Collection In LINQ Where Clause?

Apr 15, 2009

I've got the following ADO.NET Entity Framework Entity Data Model:I want to find all the Policyholders with both a Service of a given Id and also a Keyword of a given Status.

This LINQ Does Not Work:

Dim ServicesId As Integer = ...
Dim KeywordStatus As Integer = ...
Dim FoundPolicyholders = From p As Policyholder In db.PolicyholderSet.Include("Keywords").Include("Services") _
Where p.Services.Id = ServicesId _
And p.Keywords.Status = KeywordStatus _
Select p

The Where clause cannot search the p.Services and p.Keywords EntityCollections in that way.

[Code]...

View 1 Replies

Search The Collection Of A Collection In LINQ Where Clause?

Apr 15, 2011

search the collection of a collection in my LINQ Where clause?

View 11 Replies

VS 2008 Completely Customizable Controls At Runtime

Dec 25, 2009

i want to make a paint sort of program and so i have read about how to add controls at runtime. but i cant figure out how to change the properties of the control... for ex, if i add a line( that is the user clicks the line tool on the toolbar) he should be able to place it anywhere on the area available, and after that also if later he wishes to select it and resize/change color etc. it can be done.

View 4 Replies

Application Settings - Regular Expression - Customizable By The User

Oct 11, 2010

I have a little question about application settings. I have a regular expression in my code which should be customizable by the user so I made an application setting for it. The regular expression is used in a class in the project and has the following value

Dim email_regularex As String

So now I made a new Settings file in my project and gave the following value for this string in the settings file: ^([w-]+(?:.[w-]+)*)@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$ [URL]

So when i do this in Visual Studio 2008, Visual Studio automatically creates a app.config xml file with the right settings in it. But when I start my application and use the regular expression like this:

Dim

myMatch As

Match = Regex.Match(email, email_regularex)
If

[CODE]...

View 5 Replies

VS 2010 : Handles Clause Requires A WithEvents Variable Defined In The Containing Type Or One Of Its Base Types

Aug 26, 2011

I am trying to follow this thread

[URL]

and I have it pretty close but have one error.

Quote:Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

That error is on both of these, in blue

Private Sub SpellChecker1_DeletedWord(ByVal sender As Object, ByVal e As NetSpell.SpellChecker.SpellingEventArgs) Handles SpellChecker1.DeletedWord
'save existing selecting

[code]....

I have added the reference, I have also added them to the toolbox. My dictionary is all set. What did I miss?

View 1 Replies

VS 2010 Linq And Datasets

Sep 19, 2010

Checked out the video on MS website by Beth Massi and downloaded the project.

One query she uses this statement,[code...]

I'm I missing a reference or something? This is an Access DB, does that make a difference?

View 7 Replies

VS 2010 LINQ To SQL Group By?

Nov 16, 2011

In proper sql my query would be something like:

select c.id, c.name, count(i.id)
from cats c, items i
where c.id=i.catid

[code].....

View 1 Replies

VS 2010 Use Take() With Linq Expression?

Aug 6, 2011

THE CODE IS :

var query1 = ((from c in dt.AsEnumerable()
orderby c.Field<int>("1") descending
select c));
var query2 = (from c in query1.Take(10)
select c);

[Code]...

View 1 Replies

2010 : Save XML File Using Linq?

Sep 18, 2010

I need to create an application that is able to modify the XML elements value.I have an XML file which was created by another to be used for flash movie which has the following layout:

<?xml version="1.0" encoding="utf-8"?>
<games>
<game>
<gameName>Cowboy</gameName>

[code]....

As you can see there is this string "™" on <gd02>. My question is, whenever I save the file, the code changed to "TM" which is fine for most cases. But I need it to stay the same because apparently flash will not display the superscript "TM" if not using the code. How can I do this?

View 6 Replies

VS 2010 Average Time In LinQ?

Apr 9, 2011

I need help on how can I transfer a query from Access to LinQ that calculate the average in time per transaction during a given date.the working Access query is:

Avg(DateDiff("s",CVDate(Format([start_time],"hh:nn:ss")),CVDate(Format([finish_time],"hh:nn:ss")))) AS Expr1, Format([Expr1]3600,"00") & ":" & Format(([Expr1]60) Mod 60,"00") & ":" & Format([Expr1] Mod 60,"00") AS format
How can I port this to LinQ?

View 1 Replies







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