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


ADVERTISEMENT

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

Setting A Variable To Accept The Result Of A Function By Calling The Function With Many Parameters

Feb 17, 2011

I'm currently working with a client's VB.Net code, which was developed for them by a small development shop a few years ago and which they purchased and have been maintaining and uprgrading since. This client's primary developer is out on indefinite (likely permanent) medical leave and I'm now filling in until they bring in a full timer (as I'm a contractor here). My current task is to add some functionality to a the VB.Net code they purchased. I'm finding practices and techniques in the code that absolutely baffle me and can't make the code do what I want. I'm starting to wonder if it's me and was hoping to get some thoughts on the code I've encountered.

For example: Setting a variable to accept the result of a function by calling the function with many parameters, clearing the parameters in the function, setting them to some value, calling another function with those new values, then never using the values returned by the functions. I'll add a code snippet in the first comment since this is already getting long.

View 9 Replies

Asp.net - Getting The Result Of A Sql Statement In Vs2010

Nov 30, 2011

I am doing a sql statement to get all the data that starts with "A" in the database.

[Code]...

View 1 Replies

Execute A SQL Statement And Put The Result In To A Data Table?

Aug 16, 2010

I want to execute an SQL statement and put the result in to a data table.

Sub getvehicletypes()
Dim dt As New DataTable
Dim intLine As Integer = 0

[Code].....

Once Ive got it in a dataset I need to work out how to search the dataset for a code and return the corresponding description and vice versa

View 10 Replies

Select Statement That Uses Variable Result To Textbox

Jul 31, 2010

I'm relatively new to VB. I want to perform a SELECT statement that uses a variable to return a value, example;
mysql> SELECT room_description FROM room_descriptions WHERE current_room = 'someVariable';
And display the result in a TextBox i.e. TextBox.text = someVariable.
So how do I perform a query from VB that passes a variable? How do I assign the result to a variable?

View 3 Replies

Null Result In LINQ?

Apr 11, 2012

I'm having trouble with a null result, when I compare the query it said I cant it give the following error "sequence contains no elements"

Dim existe = (
p In abc.Ventadetalles
Where p.idarticulo = txtArticulo.Text

[code].....

View 3 Replies

Check When OLEDB Returned A Result From SELECT Statement?

Nov 25, 2009

In my .NET application I have to get results from a MS Access database. I would like to add error checking to make sure a row was returned from my SELECT statement.

View 1 Replies

AddHours To Linq Date Result

Sep 19, 2011

Is it possible to add some hours to linq date result ? something like this:

[Code]...

View 3 Replies

Datasource Or Linq Result To Excel?

Aug 3, 2011

i have found alot of sh*** right now. But not the things that im looking for.

I need to export a LINQ query (or the Datasource of my DataGridview)
to an existing Excel Spreadsheet. Lets Say after Cell A25

I have a Windows Form application using LINQ for the Databindings.

View 1 Replies

Xml - Error Serializing Linq Result?

Dec 2, 2010

I'm trying to serialize a LINQ result in this way:

Private Sub btnXML_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnXML.Click
Try

[Code].....

View 2 Replies

.net - Converting Linq To XML Result To Generic List?

Nov 22, 2009

I have a function that works great in C# that I'm converting to VB.Net. I'm having an issue converting the result set to a generic list in VB.net.

The code:

Public Function GetCategories() As List(Of Category)
Dim xmlDoc As XDocument = XDocument.Load("http://my_xml_api_url.com")
Dim categories = (From category In xmlDoc.Descendants("Table") _
Select New Category()).ToList(Of Category)()
Return categories
End Function

The error occurs when convertng the result via .ToList(Of Category)() The error:

Public Function ToList() As System.Collections.Generic.List(Of TSource)' defined in 'System.Linq.Enumerable' is not generic (or has no free type parameters) and so cannot have type arguments.

Category is a simple object I've created, stored in the App_Code directory.

I have the necessary "Imports System.Collections.Generic" reference in the file so I don't see why I can't convert the result set to a generic list.

View 2 Replies

.net - LINQ - IEnumerable.Join On Anonymous Result Set?

May 28, 2010

I've long since built a way around this, but it still keeps bugging me... it doesnt help that my grasp of dynamic LINQ queries is still shakey.

For the example:

Parent has fields (ParentKey, ParentField)
Child has fields (ChildKey, ParentKey, ChildField)
Pet has fields (PetKey, ChildKey, PetField)

[Code].....

The above Join call doesnt work. I sort of understand why it doesnt work, but hopefully it'll show you how I tried to accomplish this task.

After all this was done I would have appended a Select to finish the job.

I tried it with the PredicateBuilder with little success. I might not know how to use it right but it felt like it wasnt gonna handle the joining.

View 1 Replies

.net - Saving The Result Of A Linq Query To An XML File?

Nov 16, 2010

Here is the original xml file

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<setup>
<cap>33</cap>
</setup>

[Code]...

View 2 Replies

Join LINQ Query Result And Arraylist In VB

Dec 5, 2009

I have a set off LINQ queries filtering original datatable (loaded from Excel file) according to user selections in Comboboxes. Then the result is joined with Arraylist to further filter the set. Arraylist is a simple string list from 1 to 5. [Code]

View 3 Replies

Show SQL Query Result In Textbox Using LINQ 2 SQL?

Nov 15, 2011

I have a question regarding LINQ 2 SQL and data integration with textbox:I have one textbox and button on my form, one stored procedure and LINQ 2 SQL class file in my project,I want that when I hit button, my store procedure run the SQL query and show me the result in textbox.I am using VB 2008 and Visual Basic for programing.

View 2 Replies

Update Specific Rows In LINQ To SQL Result Set

Apr 6, 2010

I have a page with a form on it and needs a range of dates. Thus I've placed a number of textboxes on the page into which users can type dates. When the user clicks the save button I want to trigger a LINQ update to the SQL Server...all the rows already exist, so I'm just updating existing data.

For example, lets say my table looks like this:
Column Names: Description dateValue
Column Values:
Birthdate 1/1/1990
Anniversary 1/10/1992
Death 1/1/1993

I want to do something like this:
hupdate.Description("Birthdate").dateValue = TextBox1.Text
hupdate.Description("Anniversary").dateValue = TextBox2.Text
hupdate.Description("Death").dateValue = TextBox3.Text
hconfig.SubmitChanges()
Is there a way to do this with LINQ?

View 1 Replies

Assign Result (from LINQ To XML Query) To List(Of String)?

Jul 6, 2011

Is it wrong? Please suggest me correct way.

Public Function ReadXML() As List(Of String)
Dim list As New List(Of String)
Dim xmlDoc As XDocument = XDocument.Load("C:\MappingFile.xml")

[code].....

View 1 Replies

Equivalent To C# Var Keyword - Retrieve The Result Of A LINQ Query?

Mar 19, 2010

Is there a VB.NET equivalent to the C# var keyword? I would like to use it to retrieve the result of a LINQ query.

View 4 Replies

LINQ To XML Result Object Not Showing Extension Methods

Jan 9, 2012

I have the code as below:
Dim xdTest As XDocument = XDocument.Load(GetXMLPath())
Dim objResult = From xe In xdTest.Elements("Some Element") _
Where xe.Element("strName").Value = strInput _
Select xe.Element("intValue").Value
objResult.
I cannot access any extension methods for objResult, like .ToList() or .First(). The file imports System.Linq and the project is targeted to .NET 3.5. How do I get the extension methods back?

View 1 Replies

VS 2010 Bind Linq Query Result To Datagridview

May 9, 2012

I want to create a LINQ to entities query getting data(join) out of two tables and bind the result as datasource to a datagridview.

Unfortunately I seem to stumble upon a syntax issue.

Table 1 : dcpricing.tblpricing
Table 2 : dcpropertydetail.tblpropertydetail
Grid: grdpricing

[Code].....

View 5 Replies

Implement The .Find Method When Binding A BindingSource To LINQ (IEnumerable) Result?

Mar 15, 2008

I'm binding a DataGridView to a BindingSource to a LINQ IEnumerable, I found that the BindingSource.Find method throws an exception because .Find isn't implemented in IEnumerable (and the BindingSource just passes the call to it's DataSource). I need to use BindingSource.Find to select/highlight a particular row in the DataGridView.

Is there a feasable way to extend my DataContext to support this behavior w/o breaking anything else? I expected to find the code out there already, but I've searched exaustively with no luck.Without it, I cannot "move" the BindingSource using .Position and that's a pretty common use of the BindingSource I think.

View 1 Replies

Could Not Get Result From Sumifs Function

Jan 18, 2012

I am having trouble with using sumifs excel function in vb.net. I can use sum function with "cells" but I could not get result from sumifs function with "columns".

It is giving "OleAut reported a type mismatch." error.

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim oExcel As Object

[Code].....

View 6 Replies

Use Asc() Function To Find Result ?

Sep 22, 2011

I have a problem with Asc() function as a blow picture,I will explain each step as I do.First I convert some values to ASCII code and store in value variable, then retrieve 3rd position of variable (4th line of the picture.)

and use Asc() function to find result which it show 63. (like 5th and 6th line).But I try to manually use Chr() function, the result become 2nd and 3rd line.So for the Asc("ˆ") func. result should be 63 or 136?

View 6 Replies

.net - Result With IF() Function And A Nullable Integer?

Dec 1, 2009

I would expect the following vb.net function to return a value of Nothing, but instead its returning a value of 0.

[Code]...

View 2 Replies

Datediff Function Not Getting The Expected Result

Jul 11, 2011

I am using the following code in my project. I want to find the number of days by given the last date and now.[code] for example, when BorrowDate is "01/Jul/2011" then the result is 7 days which it should be 10 to now.

View 1 Replies

Find The Result Of A Function In The Immediate Window?

Oct 7, 2011

When I was coding a program, I was able to find the result of a function in the Immediate Window by using:

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







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