How To Return Firstchild Value In LINQ

Apr 20, 2012

Using LINQ, How do I only get the author element value for the following XML: [code]but n.value returns the author and all the child element values.

View 3 Replies


ADVERTISEMENT

Get Firstchild Node Only From Xml Document

Aug 25, 2010

I have an xml document that's looks like this

[Code]...

View 6 Replies

Using LINQ To Return Element In Collection, Would Like To Return Nothing If Element Not Found?

Mar 3, 2011

I would like the following function to return Nothing if the element with the specified key is not in the collection. Instead, it returns an error - something to the effect of "no element found"

Public Class MyCollection
Inherits System.Collections.ObjectModel.Collection(Of MyType)
Public Function FindByActivityKey(ByVal searchValue As Integer) As MyType

[code]....

View 1 Replies

Return Max Value With LINQ Query?

Nov 3, 2011

I have a method that takes in an id, a start date, and and end date as parameters. It will return rows of data each corresponding to the day of the week that fall between the date range. The rows are all doubles. After returning it into a DataTable, I need to be able to use LINQ in VB.NET to return the maximum value. How can I achieve this? Here is the initial setup?

[Code]...

View 1 Replies

Use Linq To Return A Row In A DataTable?

Jan 24, 2012

Currently, I am using a loop to find the row I want to update.

Public Sub pubsub_SetUserDGVColumnWidth(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs)
' update all user settings for the given column

[Code]....

View 8 Replies

Return LINQ Results From Function?

Jun 10, 2012

I'm trying to return a single object from an array of objects with linq.[code]...

View 2 Replies

VS 2010 LINQ Null Return?

Dec 2, 2011

I'm having trouble figuring out what to do with the bolded part, when there are no nodes to return.If there are no image tags inside the <images> tag, i get an "Object reference is not set to an instance of an object".I have been searching and searching for an answer but can't find one.

Dim orders = From o In xmlLinq.Descendants("order")
Select New With { _
.orderID = o.Attribute("id").Value, _

[code].....

View 2 Replies

Asp.net - Return Two Tables From A Stored Procedure From LINQ To SQL?

Aug 4, 2011

I have written a stored procedure like this:

CREATE PROCEDURE [dbo].[TestProcedure]
AS
BEGIN
SELECT TOP 1 CampaignID FROM Campaigns
SELECT TOP 1 ServiceID FROM Services ORDER BY ServiceID desc
END

In my .NET Project, I have a LINQ to SQL file (.dbml) and I have drag-and-dropped this procedure to create a new class TestProcedureResult:

Partial Public Class TestProcedureResult
Private _CampaignID As Integer
Public Sub New()

[Code]....

So it is not returning ServiceID. How can I retreive ServiceID using LINQ to SQL? I know we can customize stored procedure calls, but how can I customize in this particular scenario?

View 1 Replies

Detemine Sequence Has Items And If So Return Value In LINQ?

Jun 7, 2011

I currently do a lot of checks like so [code]...

however this results in two db hits. (one to determine if any and then one to calculate the sum.

View 1 Replies

How To Return Binary From DB Using LINQ To Display In Browser

Apr 1, 2009

I am trying to return a binary from the DB using linq for display in the browser. The method below using ado.net works but I am trying to ypgrade to linq but the linq version returned the error.

Public Sub ProcessRequest(ByVal context As System.Web.HttpContext)
Dim imageId As String = context.Request.QueryString("id")
Dim ret As DataTable = Nothing
ret = DPGetImageData.GetImageById(Convert.ToInt64(imageId))
For Each dt As DataRow In ret.Rows
For Each c As DataColumn In ret.Columns
[Code] .....

View 2 Replies

IEnumerable.where In Linq How To Get Obj&return Value Of Othr Func

Apr 4, 2012

How to give another function's returned value in LINQ Ienumerable.

Private function GetFruitColor(fruit) as string
'It returns fruit color.
'If valid fruit and color not available, it returns ""(empty string)

[code].....

'Below code is wrong. but please suggest me how to correct it. My intention is, I want output collection(say dictionary) of each fruitname and its color(returned by other function call) for all the fruits which the GetFruitColor is not nothing(it can be empty or valid string).

Dim query = _
fruits.Where(Function(fruit) k= GetFruitColor(fruit) if not k is nothing select fruit, k)
End Sub

View 8 Replies

Is There A Native LINQ Way To Return A Typed Collection

Apr 18, 2011

Is this the most straight forward way to return a typed collection?Here's the key line of code which returns a implicit type of IEnumerable that used to manually loop through to manually recreated a TYPED collection. Is there any native LINQ way to return a typed sorted collection without this recreating of the collection? [code]

View 2 Replies

Linq Return Results Contaiined In A List?

Mar 23, 2011

How can i select using linq from a datatable where the the only results I want back (ID's) are contained in a list of integers?

View 7 Replies

Return Column Names Of A LINQ Entity?

Feb 2, 2011

I am using LINQ to SQL queries to return data in my application. However I find it is now needful for me to return the column Names. Try as I might I have been completely unable to find out how to do this on the internet.

So if my LINQ entity table has the properties (Last_Name, First_name, Middle_Name) I need to return[code]...

View 2 Replies

Return Max Record Count By Grouping In Linq?

Nov 9, 2011

I'm very new to linq and I'm trying to come up with a linq query against a dataset that will return a max count value based on grouping records.[code]...

View 1 Replies

Return Type For Collection From LINQ Query?

Oct 15, 2010

I have a method, that returns a group of accounts

Public Shared Function GetAllNotesByUser(ByVal UserID As Guid) As Account (??)
Using db As New MyEntity
Dim query= (From A In db.Account _

[Code].....

I would then like to pass this to another function to calculate the totals for all the accounts in the collection. Is it best practice to return an Ienumerable, a generic list, I'm just not sure what works best with LINQ and the entity framework.

View 4 Replies

Using LINQ To Return First Item From Each Set Of Grouped Data

Apr 16, 2012

Given a simple DTO (AccountExpiry) with properties of 'AccountNo' and 'ExpiryDate' and a List of same created thus:
New AccountExpiry(123, New Date(2012, 4, 1))
New AccountExpiry(123, New Date(2012, 4, 2))
New AccountExpiry(123, New Date(2012, 4, 3))
New AccountExpiry(124, New Date(2012, 4, 2))
New AccountExpiry(124, New Date(2012, 4, 3))
New AccountExpiry(124, New Date(2012, 4, 4))

How do I use LINQ to retrieve the most recent entry per account. I have a feeling this will involve GroupBy and FirstOrDefault. It seems like...
From Item In Source Group By Item.AccountNo Into Group
Should return all of the data grouped appropriately, but It is unclear how I might apply .FirstOrDefault to each group.

View 1 Replies

LINQ Objects - Group All The MyObjects Together That Share The Same Value And Then Return That Value?

Nov 16, 2010

I am having trouble following some of the examples at MSDN for LINQ.Basically I have a List Of MyObject. MyObject has a property called Value which is an integer.I want to group all the MyObjects together that share the same Value and then return that Value where the count of the group is greater than 5.I have tried the following,

dim foak = From o as MyObject in MyObjectList _
Group o By o.Value into Count _
WHERE Count > 5 _
Select o.Value

View 2 Replies

LINQ Stored Procedure Return Value To A String Array?

Mar 24, 2011

I have a stored procedure in DBML and I try to pass the result to "sqlQryArray" as an array(1 dimensional array). But the bottom code causes error like below message. What else should be done?

Error 1 Value of type '1-dimensional array of aaaDatabase.stp_GetSomethingResult' cannot be converted to '1-dimensional array of String' because 'aaaDatabase.stp_GetSomethingResult' is not derived from 'String'.

The return result from stored procedure is a just list of first names of students(only one column)

Dim sqlQry = aaaLINQ.stp_GetSomething(bbb,ccc,ddd)
Dim sqlQryArray As String() = sqlQry.ToArray()

View 2 Replies

LINQ Return Single Type Of Object Invalid Cast

Jun 29, 2010

Ok, just needing a 2nd set of eyes looking at this to make sure the error isn't something else other than my LINQ code here. Here's the function class itself:

Public Function GetJacketByPolicyID(ByVal jacketID As Int32) As tblPolicy
Dim db As New DEVDataContext()
Dim j As tblPolicy = db.tblPolicies.Single(Function(p) p.policyNumber = jacketID)
Return j
End Function

and here is the code which calls this class function in the web control form itself:

Dim p As tblPolicy
Dim j As New Jackets()
p = j.GetJacketByPolicyID(3000050)

For some reason it's flagging the 2nd line in the GetJacketByPolicyID function saying the specified cast is not valid. So I'm guessing it's something I'm doing wrong. I'm sure the tblPolicy/tblPolicies class works right since I can create a new instance of a tblPolicy and set a few variables by hand and return it, so that's not it. I've also checked the datarow I'm fetching and there's no null values in the record, so that shouldn't be it either.

View 1 Replies

Linq To SQL - How To Return Values For A Single Date In Datetime Format

Nov 30, 2011

I am trying the following to select a long date, but becase the value is stored in SQL database as DateTime I am unable to return any results unless minutes and seconds match perfectly...I then tried to use 2 calendars and have the same issue with the DateTime format..

CODE:

View 1 Replies

Using LINQ To Query XML And Return Empty String If No Data Is Present?

Mar 8, 2011

What I'm trying to do is to write a generic rss reader that I plug in any URL into without worry if the feed has all the common properties. For instance in my example below I'm looking for pubDate, however if no pubDate exists in the xml I'd like to return the current Date. I cannot seem to get the syntax right though.

Dim xmldoc As New XDocument
xmldoc = XDocument.Load(url)
Dim feeds = From feed In xmldoc.Descendants("item") Select New With { _

[code].....

View 2 Replies

VS 2008 - LINQ Query Against A Typed Datatable That Will Return Me Duplicated Data?

Jan 25, 2010

I'm trying to do a LINQ Query against a typed datatable that will return me duplicated data.With out going into too much detail, here's the basic setup:

strCode1 - string type
intCode1 - int32 type
intAdjustor - int32

There are more fields but these are the ones that are important.I'm going to do my best to describe this, as it's kind of confusing.In theory intCode1 is a key for strCode1 (hence the names). So each time intCode1 is duplicated, the same strCode1 should appear. Example:

[code]...

Ultimately I'd like to get a List(Of T) - where T is my typed data row. In SQL, I would simply use a sub query, to get a distinct list of strCode1 and intCode1, then do a count, grouped by strCode1 where I get more than one row.I'm not sure how to translate that into LINQ, AND get the original types data rows returned in a list.

View 7 Replies

Use Linq ToDictionary To Return A Dictionary With Multiple Values In The Dictionary Items?

Jan 25, 2010

I want to group items from a linq query under a header, so that for each header I have a list of objects that match the header title. I assumed the solution would be to use ToDictionary to convert the objects, but this allows only one object per "group" (or dictionary key). I assumed I could create the dictionary of type (String, List Of()), but I can't figure out how to write it. As an example I have written a simplified version below.

[Code]...

View 2 Replies

Linq Join Typeddatatable With List And Return Typeddatatable?

Nov 3, 2010

I hava a strongly typed datatable and a list(of String). I want to build a linq query to return a datatable of the same type where the fields of a certain column of the table are in the list. I thought of doing a Join, although in normal sql I would have addedSELECT FROM Table WHERE Table.ID IN(...);This is what I tried in linq.

Dim Families As List(Of String)
Dim Articles As SomeStronglyTypedDataTable
Dim MatchingArticles = From a In Articles.AsEnumerable _

[code].....

View 3 Replies

[VB 2010] Return Alert Message If SQL Query Return No Records

Dec 12, 2011

I use this code to return records in a DataGridView:

[Code]....

View 3 Replies

Return An Object As The Return Value Through A RealProxy Transparent Proxy?

Oct 7, 2010

I'm working up a system where I plan on using RealProxy objects to enable intercepting method calls against a set of objects, handling the call, and then returning appropriate results. This works just find for simple return types like strings or ints, but I can't seem to return objects from the RealProxy.Invoke method. Everything works. I get no errors, but the returned value is always NOTHING, instead of an object.

I've worked up the smallest sample code I could, and have included it below. Essentially, just call RPtest and single step through. The code creates a simple object, RPTestA, with a string field and an object valued field It then retrieves the string

[Code]...

View 1 Replies

.net - ActiveRecord Linq/NHibernate Linq Not Building Query Completely?

Jul 14, 2011

given this function:

Public Function Search(ByVal StartIndex As Integer, _
ByVal MaxResults As Integer, _
ByVal AccountNumber As String, _
ByVal LastName As String, _

[Code]....

instead of what I expected:

Select count(*) from remitline where lastname = "smith"

What am I doing wrong building up the where clause? I'm using Castle ActiveRecord 2.1

View 1 Replies

Performance Gain In LINQ Query Vs LINQ Stored Procedure?

Aug 6, 2009

if there is that much of a performance gain in running a LINQ stored procedure versus a LINQ query?

View 1 Replies

Checking If A Port Is Open - If It Is Open Then Return True, If It's Closed, Return False?

Dec 28, 2010

I'm making a Visual Basic GUI application to display whether a number of my ports are open for people to know whether things like my website and my Minecraft server are open.My problem is I have absolutely no idea how to do this in Visual Basic.Basically, I'm asking for something which sends a signal to an IP with a specific port, if it is open then return true, if it's closed, return false. Similar to: http:[url]....

View 1 Replies







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