Use If Statement During Select From Linq To Datasets?

Dec 14, 2009

I have this LINQ statement [code]...

Is there any way that I can use if/iif within select ?

View 1 Replies


ADVERTISEMENT

Sql - Perform An Inline Select Statement In A LINQ Statement?

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

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

How To Write A SQL Statement Programmatically With Datasets

Mar 29, 2009

How do i programmatically execute a SQL statement using datasets?

View 6 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

(Linq To Datasets) Dynamic Querying In .net?

Jan 24, 2010

I have been looking into dynamic querying of datasets and the use of copytodatatable() for a project. I have seen in alot of forums that the copytodatatable functionality is unusable as it was removed. have an example of a dynamic Linq query being loaded into a datatable.

View 1 Replies

Linq To Datasets Null Values On Integers?

Feb 21, 2010

If I have a datatble column set as int16 but rows can contain null values for this column. How do i write the linq query. I keep getting an error null value exception. Dim query = From n In resultstable.AsEnumerable Where n.value is dbnull.value does n't work.

View 6 Replies

ElseIf Statement Into A Select Case Statement?

Jun 23, 2010

A co-worker wants to convert the following IfThenElseIf statement into a Select Case statement.
Explain why this is not possible.

If temperature = 100 Then
X = 0
ElseIf population > 1000 Then
X = 1
ElseIf rate < .1 Then
X = -1
End If

View 7 Replies

Database - ID Select ,select Statement?

Mar 23, 2012

have a table with following fields

Emp_id varchar(50)
Emp_Name varchar(50)
Emp_surname varchar(50)

[code].....

View 1 Replies

Use A SELECT Statement To Select All Data?

Apr 2, 2009

I need to use a SELECT statement to select all data under a column name (like all employee names) and then to add the values to a listbox.

I usderstand that the select statement must be:

"SELECT * FROM EmployeeTable WHERE EmployeeNames LIKE *" (at least I think)

but then what? combobox1.fill ("EmployeesTable") ?

View 9 Replies

Database - Compare Two Fields In An SQL SELECT Statement To Then Select Other Fields Based On This Result?

Apr 8, 2012

I have a table which contains a list of products for a company. They input data about how much stock they have and also the level at which they want to be reminded that they need to order new stock.

[Code]...

I want to list all the true results in a form which the user is then able to navigate through. What would be the best way to go about doing this?

View 2 Replies

.net - Linq Query If Statement?

Jun 24, 2011

Ok im trying to do a if statement in Linq and was wondering if it was possible to do something like:

Dim loadFriends = From p In db.UserRelationships Where p.aspnet_User.UserName = User.Identity.Name _
Or p.aspnet_User1.UserName = User.Identity.Name And p.Type = 1 _
Select New With {if p.aspnet_user1.user = "a certan username" then .username = _
p.aspnet_user.username else .username = p.aspnet_user1.Username}

[Code]...

View 1 Replies

.net - XML Literal With Linq Statement?

Oct 7, 2009

I am going to be performing an XSLT transformation, transforming XML to an HTML table. It's tabular data, so that's why I'm not using div's.

[Code]...

View 3 Replies

Is There A Better Way To Do LINQ Statement Block

Aug 13, 2009

I'm relatively new with LINQ, but I'm going to be getting into it a lot more. Is the following a practical application of LINQ, or is there a better way to do something like this? [code] I was thinking if I could get the property name somehow as an object I could just do one LINQ statement,

View 5 Replies

LINQ Where Statement In Collection?

Mar 28, 2012

I have a Customer object which has a collection of ContactNumbers. Is it possible with LINQ to get a list of Customers where one of the contact numbers = '123'?

Public Class Customer
Public Overridable Property ContactNumbers As List(Of ContactNumber)
End Class

[Code].....

View 1 Replies

Convert The Following VB Code To A LINQ Statement?

Oct 8, 2009

I only want to return a certain number of rows into the DataTable via LINQ's Take or use it on the Rows property, but I am not sure how or where to do it: Here is the current code:

Dim dt As DataTable = GetDataTable("sp", params)
For Each dr As DataRow In dt.Rows
Dim o As New OR()

[code].....

View 1 Replies

Getting Result Of Linq Statement Out Of A Function?

Jun 16, 2011

I have something that I want to do and what looks very simple, but I cannot get it to work. I want to build a function that gets as input a xdocument and some other strings. It should have a return that contains a filtered part of the xdocument in a way that I can use it as input for a new Linq function. This is what I mean:

Private Function fncGetFilteredDecendantsOfNode(ByVal xdocDoc As XDocument, _

[Code]...

View 2 Replies

How To Turn Query Into A LINQ Statement

Sep 30, 2009

How can I turn the following query into a LINQ statement? [code]

View 1 Replies

LINQ Statement Not Updating Database?

Jul 15, 2010

I have the following code:[code]When I run it, looking at the debugger everything looks okay but when I check the database table it is supposed to be inserting into - the column values (for occupantnum) haven't changed - they are all still null! Not sure if this is related, but note that I've now updated j to explicitly be an integer. I noticed while debugging that wResident.occupantnum was appearing as Type "Integer?" - but this doesn't seem to have made any difference - when I rerun it it still says Type "Integer?"

View 4 Replies

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

Tell If A LINQ To SQL Query Is Translated To A SQL Statement Or Not?

Oct 15, 2010

We use LINQ to SQL extensively, and one of the biggest performance pitfalls we've run into is situations where a query can't be converted to SQL, and so an entire database table gets loaded into memory and the query performed by .NET. For example, this query

Dim Foo = (From c in Db.Contacts Select c Where c.ContactID=MyContactID)
translates to a simple SQL query, whereas
Dim Foo = (From c in Db.Contacts Select c Where c.ContactID=SafeInt(MyContactID))

doesn't because SafeInt is our own function and doesn't have a SQL equivalent; so the whole contacts table gets loaded into memory and searched by LINQ to objects, which is vastly slower. With a little experience, we've gotten better at avoiding this kind of situation. But it's not always obvious, and this is the sort of problem that's often not revealed until you're working with a lot of data and things start to slow down. Is there a straightforward way to see - whether in Visual Studio or some other way - how LINQ queries will be handled, other than trial and error?

View 3 Replies

VS 2008 Convert SQL Statement To LINQ?

Oct 28, 2009

I'm just getting my feet wet with LINQ but am struggling to convert this SQL statement to LINQ.

Dim SQLString As String = "SELECT MESSAGE_ID FROM " & Schema & _
".PPM_TRANSFER_EMAIL WHERE TO_CHAR(IMPORTED_DATE,'YYYY/MM/DD') <= '" & _
DeletionDate.ToString("yyyy/MM/dd") & "' AND IMPORTED = 'Y' AND FILE_NAME LIKE '" & _
mb & "%'"

I have a Dataset that already contains all the data from the PPM_TRANSFER_EMAIL table so it seems silly to query the database again when I can use LINQ to query the dataset.

View 1 Replies

Select Statement In .NET?

Jul 2, 2010

with the following code which gets stucked on the line of reader = Cmd.ExecuteReader(). It says the SqlException was unhandled (An expression of non-boolean type specified in a context where a condition is expected, near '7/2/2010'.)

[Code]...

View 2 Replies

SQL Select And Where Statement In VB

Jan 8, 2010

I have successfuly connected to a database and have create a select statement (with access) which works most of the time except when im trying to perform a where statement with a date:

strEmployeeDepartmentLocation = Application.StartupPath
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " & strEmployeeDepartmentLocation & "swineFlu.mdb"
strSQLSelectQuery2 = "SELECT NumberOfCase FROM table1 WHERE Date = 21/04/2009;"

i dont no if im writing it in the wrong format or what but it dont seem to bring back any data

View 6 Replies

Asp.net - Binding Different LINQ Datasource Using Same Variable W/ If Statement?

Nov 27, 2010

OK So I know WHY I am having the error I am getting. I don't know HOW to fix it. Basically, if the user doesn't have a certain permission, I need to join another table. But .NET is so picky I can't just make two different queries in an IF statement and then use it outside of the if statement. I can think of some ugly work arounds for this, but I would rather not. I am fairly new to .NET I know just enough to be dangerous.

[Code]...

because of this: Dim l As IEnumerable(Of Company) its not just IEnumerable of a Company, its got the source in it. I have to explicitly select source to use it in my datagrid. Can I make Dim l something that will make it stop complaining?

View 2 Replies

Execute A LINQ Statement Without Assigning It To A Variable?

Apr 15, 2011

I have the following function

Public Function GetPositionBySchoolID(ByVal SchoolID As Integer) As CPAPositionsDataTable
Dim positions As New CPAPositionsDataTable

[Code]....

And I was wondering if there is any way to cut out assigning the LINQ result to tmp and just work with the result directly, i.e.

Public Function GetPositionBySchoolID(ByVal SchoolID As Integer) As CPAPositionsDataTable
Dim positions As New CPAPositionsDataTable

[Code].....

View 2 Replies

LINQ To DataTable Error - End Of Statement Expected

Sep 21, 2010

If txtSearchString.Text.Trim <> "" Then
Dim searchString As String = txtSearchString.Text.Trim
Dim results As EnumerableRowCollection(Of DataRow) = From PO In FilterPurchaseOrders().AsEnumerable

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

I am getting this error: error BC30205: End of statement expected.

FilterPurchaseOrders() function returns a datatable.

Whats wrong with the above code?

View 2 Replies

Specify Database Column That Contains A Space In A Linq Statement?

Jun 23, 2010

I thought this would have been quite common but can't find anything on this. I'm trying to query columns that have spaces immbedded within them. For the life of me I don't see a way of selecting them when I'm trying to assign them to an alias when creating an anonymous type result. [code]...

View 1 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

DataTable Select Statement?

Apr 9, 2012

I have a datatable and I would like to get the MAX number from this table where Term Number (first Column) is a certain value. If my datatable is declared as dtMyTable, I'm assuming I need to use dtMyTable.Select(), but I'm not sure if this is the best way.

View 2 Replies







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