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


ADVERTISEMENT

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

C# - Convert Code LINQ To SQL In C # LINQ To SQL In .net?

Jun 27, 2012

How can I convert this code LINQ to SQL in C # LINQ to SQL in Vb.net

[Code]...

View 2 Replies

How To Convert Code To LINQ

Feb 21, 2009

I'm trying to write this as LINQ, [code]I'm a LINQ beginner, so far I'm not quite sure where to use and where not to. If in this case LINQ will do more harm then help, feel free to flame me.You can assume that there is an overload for AddLink() which takes IEnumerable

View 2 Replies

Linq Stored Procedure - Convert C# Code ?

Feb 3, 2010

Can convert this c# code to vb.net code.

DataClassesDataContext dc =
new DataClassesDataContext();

//proc_GetExistProductDetails is a Stored procedure method from my DataContext class.

[CODE]...

View 6 Replies

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

Easier To Convert C# Asynchronous Socket Code Into .net Than Convert .net Code To C#?

Dec 8, 2009

my project was intially mandated to be done in c#.however a large contributor to the project wrote much of the business logic, which he knows well, in vb.net.How difficult would it be to convert the following c# code into vb.net.

[Code]...

View 5 Replies

Convert An Object System.Data.Linq.DataQuery To System.Linq.IQueryable?

Oct 21, 2009

How can I convert an object of type System.Data.Linq.DataQuery to System.Linq.IQueryable?I'm working with Visual Basic/Silverlight, and the source code of my query is as follows:

Public Function Get_Cli_Pag() As IQueryable(Of V_Cliente_Pagare)
Dim Qry = From P In Me.Context.Pagares Join C In Me.Context.Codigos On C.Codigo

[code]....

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

Break Up The Code In A Method Body Into Statement By Statement Symbols/"tokens"?

Apr 22, 2011

I'm writing something that will examine a function and rewrite that function in another language so basically if inside my function F1, i have this line of code var x=a.b(1) how do i break up the function body into symbols or "tokens"?I've searched around and thought that stuff in System.Reflection.MethodInfo.GetMethodBody would do the trick however that class doesn't seem to be able to have the capabilities to do what i want..dit 2:basically what I'm trying to do is to write a program in c#/vb and when i hit F5 a serializer function will (use reflection and) take the entire program (all the classes in that program) and serialize it into a single javascript file. of course javascript doesn't have the .net library so basically the C#/VB program will limit its use of classes to the .js library (which is a library written in c#/vb emulating the framework of javascript objects)

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

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

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

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

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

Asp.net - Create A LINQ Statement Where The Table Name (FROM) And Column Name Is Variable?

May 11, 2012

In my programming task I've gone down a dark alley and wished I hadn't, but there is no turning back now.

I'm building up a SQL statement where the table name, column name and id value are retrieved from query string parameters i.e. ("SELECT [{0}] FROM [{1}] WHERE [Id] = {2};", c, t, id)

But it isn't as bad as it looks, I'm protected: Only authenticated users (i.e. signed in users) can execute the Page_Load I'm checking that both the table and the column exists beforehand (using GetSchema etc.)I'm checking that the Id is an integer beforehand All my tables have Id columns The database connection is reasonably secure

[Code]...

View 1 Replies

LINQ Statement Where Result Count Is Used In Expression's Condition?

Mar 23, 2009

I have a requirement where I have to add items into a List(Of T) (let's call it Target) from an IEnumerable(Of T) (let's call it Source) using Target.AddRange() in VB.NET.

Target.AddRange(Source.TakeWhie(Function(X, Index) ?))

The ? part is a tricky condition that is something like: As long as the as yet unenumerated count is not equal to what is needed to fill the list to the minimum required then randomly decide if the current item should be taken, otherwise take the item.Somethig like...

Source.Count() - Index = _minimum_required - _curr_count_of_items_taken _
OrElse GetRandomNumberBetween1And100() <= _probability_this_item_is_taken
' _minimum_required and _probability_this_item_is_taken are constants

The confounding part is that _curr_count_of_items_taken needs to be incremented each time the TakeWhile statement is satisfied. How would I go about doing that? I'm also open to a solution that uses any other LINQ methods (Aggregate, Where, etc.) instead of TakeWhile.If all else fails then I will go back to using a good old for-loop =)

View 2 Replies

Sql - Dynamically Varied Number Of Conditions In The 'where' Statement Using LINQ?

Feb 3, 2010

I'm working on my first project using LINQ (in mvc), so there is probably something very simple that I missed. However, a day of searching and experimenting has not turned up anything that works, hence the post.

I'm trying to write a LINQ query (Linq to SQL) that will contain a multiple number of conditions in the where statement separated by an OR or an AND. We don't know how many conditions are going to be in the query until runtime. This is for a search filter control, where the user can select multiple criteria to filter by.

select * from table
where table.col = 1
OR table.col = 2
OR table.col = 7
'number of other conditions

Before I would just construct the SQL query as a string while looping over all conditions. However, it seems like there should be a nice way of doing this in LINQ. I have tried looking using expression trees, but they seem a bit over my head for the moment. Another idea was to execute a lambda function inside the where statement, like so:

For Each value In values matchingRows = matchingRows.Where(Function(row) row.col = value)However, this only works for AND conditions. How do I do ORs?

View 3 Replies

What's Equivalent Syntax For Anonymous Types In A LINQ Statement

Jun 29, 2010

I'm trying to translate some C# LINQ code into VB.NET and am stuck on how to declare an anonymous type in VB.NET.[code]How do you translate C#'s new { ... } syntax into VB.NET?

View 2 Replies

Convert C# Statement To .NET?

Dec 22, 2009

convert this C# to VB.NET? convert it manually (translators are not doing a proper job for this) or at least let me know step by step what is happening in this statement so I can do the approrpriate translation myself.

async.PostOperationCompleted(
delegate(object e) { OnMyTaskCompleted((AsyncCompletedEventArgs)e); },
completedArgs);

View 4 Replies







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