LINQ - Querying Top 5 With Rank Number?

Jun 29, 2010

How do I return a top 5 with rank number using linq?

Dim Top5 = From A In DAO.Cache.Select(Of VO.Empresa).Take(5) Select A.Nome

I would like this result:

Rank Name
1 "Example Name"
2 "Example Name"
3 "Example Name"
4 "Example Name"
5 "Example Name"

View 3 Replies


ADVERTISEMENT

Querying XML With LINQ By Attribute?

Mar 2, 2012

Given the following XML file:

<users>
<user name="admin" password="foobar" roles="Admin,Guest" />
<user name="guest" password="foobar" roles="Guest" />
</users>

How do I find a specific node? In this case I want to find the node that has its name attribute to be "admin"

Dim authGroup As XElement = XElement.Parse(myXMLDoc.OuterXml)
Dim foundUser As IEnumerable(Of XElement) = From i In authGroup.Elements Where i.Attributes("name") = "admin" Select i

[Code].....

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

Wpf - Linq Querying For User Search?

Mar 10, 2012

I am trying to query from search box using list of data and the linq I used is:data = (From k As BSPLib.ContactLib.Contact In data_org.Values Where k.stringdata Like "%" & Searchtxtbox.Text & "%" Select k.prime).ToListBut this is not working, I am getting no data at all. Data_org is a dictionary so I used the values; k.stringdata contains all the data that need to be searched. Searchtxtbox.text contains the user defined search item.I Tried with sqlmethods through linq, but sqlmethods does not exist for me, I tried with with Imported namespace yet the code is not showing sql methods, could you please provide a workable query or just tell me where I have gone wron

View 2 Replies

Querying An Array Of Invoice Objects (LINQ)?

Sep 19, 2009

I am having a little problem with some homework. Here is the problem:Use the Invoice Class provided to create an array of Invoice Objects. Class Invoice includes four properties- a PartNumber (type integer), a PartDescription (type String), a Quantity of the item being purchased (type Integer), and a Price (type Decimal). Write a Console Application that performs the following queries on the array of Invoice objects and displays the results:

[Code]...

View 3 Replies

Querying An Entity That Has A Varbinary Field With LINQ?

Jun 5, 2012

When I try to query an entity that has a varbinary field in it I am getting error:"The LINQ expression node type 'ArrayIndex' is not supported in LINQ to Entities."

Here is my query:

Dim query = From entity In db.Entity
Where entity.Id= Id
Select entity.VarBinaryField

[code]....

The error gets generated when I check that the query isNot nothing.

View 1 Replies

VS 2008 - Querying Array Of Invoice Objects (LINQ)

Sep 20, 2009

Use the Invoice Class provided to create an array of Invoice Objects. Class Invoice includes four properties- a PartNumber (type integer), a PartDescription (type String), a Quantity of the item being purchased (type Integer), and a Price (type Decimal). Write a Console Application that performs the following queries on the array of Invoice objects and displays the results:

a. Use LINQ to sort the Invoice Objects by PartNumber
b. Use LINQ to sort the Invoice objects by Price
c. Use LINQ to select the PartDescription and Quantity and sort the results by Quantity
d. Use LINQ to select from each Invoice the PartDescrition and the value of the Invoice (i.e. Quantity * Price). Name the calculated column InvoiceTotal. Order the results by InvoiceTotal.
e. Using the results of the LINQ query in Pard d, select the InvoiceTotals in the range of $200 to $500

I am pretty sure I have parts a, b, & c completed correctly. Or at least the provide the desired results. Part d I figured out how to multiply the 2 fields but can't create a new column for the result or figure out how to show the PartDescription with the multiplied result. Part c I think I can figure out when I get part d. I already coded what I think will work for part c.

Below are the 2 Objects the Invoice was given and not to be changed & the LINQ is the one I have been working on.
Module LINQ
Sub Main()
' array of invoices
Dim invoices As Invoice() = { _
New Invoice("83", "Electric Sander", "7", 59.98), _
[Code] .....

View 3 Replies

Sql - Querying Two Tables - Count The Number Of Records That Match On The GIDs From The 'Directories' Table

May 5, 2011

I need to count the number of records that match on the GIDs from the 'Directories' table (GID) and the 'ClientSubscriptions' table (DirectoryGID), and also the 'FranchiseGID' from both; as follows:

Dim iSubscriptionCount

SQLCommand = "SELECT COUNT(*) AS Counter FROM Directories.GID, ClientSubscriptons.DirectoryGID FROM Directories, ClientSubscriptons WHERE Directories.GID = ClientSubscriptons.DirectoryGID;"

[CODE]...

I need to determine whether or not to show a menu option based on the above.

Full Code: Default.asp

<!--#include virtual="/System/Startup_Admin.asp"-->
<!--#include virtual="/Admin/FranchiseAdmin/DirectorySetup/i_Directory.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-

[CODE]....

View 3 Replies

How To Calculate Rank

Nov 2, 2010

i preparing a student marklist in vb.net,how to calculate rank (total,res(pass))wise,plz anybody send rank calculation coding

View 1 Replies

How To Rank Variables

May 10, 2009

Is there an easy way to rank variables. Currently I have to compare each one to each other then try to eliminate one. Is there an easy code.Say x y z are all numbers. To find the highest I have to

if x > y and x > z then ....
else y > x and y > z then....
else z > y and Z > x then...

this isnt' too bad with three variables, but if I have 10 or more it gets long... and then finding if x is first, finding what is the second highest is tough too

View 5 Replies

Rank Student From Their Obtained Marks?

Jun 8, 2009

SELECT COUNT(StudentId) FROM firstterm where class='Nursery'

SELECT percentage, StudentId FROM firstterm WHERE class= 'Nursery' ORDER BY percentage DESC

this shows result like this[code]...

now in the form i put the 2 text box and and the buttoni take the number 10003 and click the buttonnow in the another text box i need to show that what is the position of the id number 100003 from the above figer it is in the third position

how can i make it through the click button so the the result comes on the front

View 9 Replies

VS 2010 : Make A Rank Calculator?

Sep 8, 2011

VS 2010 : make a Rank Calculator?

View 2 Replies

Calculating Rank From Saved Database Result

Mar 24, 2009

StudentId Marks obtain class
1001 76 NINE
1002 75 NINE
1003 55 NINE
1004 62 NINE
1005 38 EIGHT
1006 56 EIGHT
1007 31 EIGHT
1008 57 NINE
1009 48 EIGHT
1010 55 NINE
1011 49 NINE
1012 49 EIGHT
1013 27 NINE
1014 31 NINE
1015 48 NINE
1016 58 NINE
1017 31 NINE
1018 36 NINE

This is my database now I want to calculate rank from above this. I call this through procedure. If I select id 1001 then it will display the rank from the above data base. If I select 1007 then it must display rank to class eight.

View 10 Replies

Sorting - Change Rank Property Of MyClass By Last Changed Item In OXT

Feb 22, 2011

dim oXT As New Generic.SortedDictionary(Of String, MyClass)

[Code]...

View 4 Replies

Asp.net - LINQ To Objects Auto-increment Number?

Feb 25, 2009

This feels like a completely basic question, but, for the life of me, I can't seem to work out an elegant solution.

Basically, I am doing a LINQ query creating a new object from the query. In the new object, I want to generate a auto-incremented number to allow me to keep a selection order for later use (named Iter in my example).

Here is my current solution that does what I need:

Dim query2 = From x As DictionaryEntry In MasterCalendarInstance _
Order By x.Key _
Select New With {.CalendarId = x.Key, .Iter = 0}

[Code]....

Is there a way to do this within the context of the LINQ query (so that I don't have to loop the collection after the query)?

View 3 Replies

Sql - LINQ Or DataTable When Number Of Fields Unknown

Feb 25, 2010

I have a dynamic query which returns a DataTable. This DataTable will contain a varying number of columns depending on the selection used in the query. I want an efficient way of filtering the records in the DataTable.

For Example The DataTable contains columns : A, B, C and D

I need to query this data at serveral points in my program. At some point I may need records where A=10 and C>40. At another point I may need records where A<10 and D=90 etc.etc. The selects are dymanmic, I do not now what Columns or values are needed until the code is executing.

I could simply use a DataTable Filter and build the selection string dynamically. I have no problem with this. However I was wondering if using LINQ would be more applicable. I am completely new to LINQ and would like to use it but don't know its capabilities.

(At present I am using a DataTable but in future this may change to a collection of Objects)

View 1 Replies

.net - Use LINQ To Count The Number Of Combinations Existing In Two Lists?

Jun 17, 2010

I'm trying to create a LINQ query (or queries) that count the total number of occurences of a combinations of items in one list that exist in a different list. For example, take the following lists:

CartItems DiscountItems
========= =============
AAA AAA

[code]....

The result of the query operation should be 2 since I can find two combinations of AAA and BBB (from DiscountItems) within the contents of CartItems.My thinking in approaching the query is to join the lists together to shorten CartItems to only include items from DiscountItems. The solution would be to find the CartItem in the resulting query that occurs the least amount of times, thus indicating how many combinations of items exist in CartItems.When CartItems is filtered to only the items in DiscountItems, it can be visually displayed like this:

CartItems that get a discount
=============================
AAA BBB <= This combination is eligible for a discount
AAA BBB <= This combination is eligible for a discount
AAA <= Not eligible

Thus, because there are 2 combinations of the discount in the Cart, the result is 2.Here's the query I already have, but it's not working. query results in an enumeration with 100 items, far more than I expected.

Dim query = From cartItem In Cart.CartItems
Group Join discountItem
In DiscountGroup.DiscountItems

[code]....

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

.net - Write A Linq To Sql Query To Find Records Where Field Name Can Match One Of Dynamic Number Of Strings?

Mar 21, 2012

I have users check off lab facilities in a UI. I want to use linq to fetch corresponding records for all of the labs that they have checked off. Basically,

Dim myRecs = (From l As EpiData In myDataContext.EPIDatas Where l.facility= _
one of the checked labs

So basically, I need to write a linq query where the "strings" to match are determined at runtime. Is there any way to do this easily? I know that there is a library out there called dynamic LINQ, but (1) it's in C# and I'm writing in VB (2) I'm really just looking for a single, simple solution for this single case.

View 1 Replies

VB 2010 - Rank The Data - Divide The Data - Find The Median

Oct 14, 2010

There are few steps to find out the half slopes of the graph.

Step 1: Rank the data The independent variable is required to rank it from the lowest to the highest.

Step 2: Divide the data Divide the sample size into 3 roughly equal parts, which is the lowest, middle and the highest parts. If n/3 has remainder of 1, +1 into the middle part. If n/3 has remainder of 2, +1 into the lower part.

Step 3: Find the median The size of each part = n, find the ((n+1)/2)^th value for both dependent and independent variables. If the ((n+1)/2)^th is not an integer, sum up the 〖n/2〗^th value and ((n+2)/2)^th value and divide the total by 2 to make it as median. The median, m1 for independent variable in lower part indicate as XL , middle part median, m2 as XM and the highest part median m3 as XH. For the dependent variable the median is indicate as YL, middle part as YM and the highest part as YH . Figure 3.2 Example of median m1, m2 and m3

Step 4: Find the half slope Find the half slope for the lower half, b_L=(Y_M-Y_L)/(X_M-X_L ) and for the upper half, b_H=(Y_H-Y_M)/(X_H-X_M ) .

Step 5: Find the half slope ratio, b_0=b_L/b_H . If the ratio is negative, the dependent variable need to add with a constant, c in order to make the slope same direction.

Step 6: Identify transformation. Depend on the graph pattern pick one type of transformation which is nearest to the original of the variable.

Step 7: New half slope Find out the new half slope ratio, b1 by repeat step 4 and 5 with the transformed variable.

Step 8: Repeats steps Repeat step 6 and 7 with choose the transformation which is nearest to previous transformation and find the new half slope ratio, b2, b3,�, bn. Repeating this step until |1-b_i |≤|1-b_j |, for i<j, i and j = 1,2,3,

Step 9: Result bi is chosen. The data transformation used in bi is the most closest to be normality.

How to make it into visual basic and let it run by the program?

View 5 Replies

VS 2008 - Pull The #'s Between: <REACH RANK=" And "/> With Regex?

Jan 20, 2010

i am trying to parse the following:

[code]...

If I wanted to pull the #'s between: <REACH RANK=" and "/> how would I do this with regex? I tried it, and it'd say "Too many: )'s"....then i'd remove it...then it'd say: "Too Few )'s".

View 2 Replies

Error When Querying DB?

May 25, 2009

IErrorInfo.GetDescription failed with E_FAIL(0x80004005).I get this error when trying to send a query to a database. Its an access 2000 DB. Google suggests the error indicates that I am using a vb keyword as a field name or table name. I have checked with these here and can't see anything that matches.

View 6 Replies

Querying DataGridView Using SQL

Apr 12, 2010

I'm using VB.net for a project i'm building for a friend. He has access to data on all the schools in our country and also data on the local area Authorities which run these schools. I have a database with two related tables; 'TBLlocalauthority' and 'TBLschools'. Each localauthority can have several schools, but each school can only have one local authority.

[Code]...

View 8 Replies

Querying IIS Using A VB Application?

Sep 10, 2010

Is there a particular class in .NET available that will allow a user to query IIS to see what websites are running on the local server? I would like to try to write a simple program that programmitically lets me know which websites are running in IIS along with some basic information about them. Can this be done in VB?

View 3 Replies

Querying Sql Server From VB?

Jun 15, 2011

Whenever I have

Dim catID as integer

And I use this in a query like this:

cmd.CommandText = "select * from categories where parentid='" + catID + "'"

I get:

Conversion from string select * from categories where p to type Double is not valid.

Why is it so?The parentid datatype in sql is integer.

View 3 Replies

VS 2008 Querying SQL With VB?

Aug 7, 2010

My form has a DateTimePicker and a DataGridView on it. I need to have it query a SQL Server DB and return the table to the DGV. The query is to search the Date_Joined field for date less than the date that the user input with the DTP. With the code below, my DGV is populated with all data and not the filtered data I need. I also have added a Go button for the purpose of execution instead of using the ValueChanged sub for the DTP.

Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
Dim query As String
'dtpDateJoined is a DateTimePicker on the form

[code].....

View 6 Replies

Asp.net - Re-use An Ado.net Datatable So As To Avoid Re-querying?

Jun 11, 2011

Is it possible to re-use a DataTable in .net? Here's an example from code-behind:

[Code]...

View 3 Replies

Error With SQL Statement While Querying The DB?

May 28, 2009

I have some sql statement error while querying the DB and to display the result on a data grid view. Could someone check the codes below and let me know the problem with the codes.

Dim cm As New System.Data.OleDb.OleDbCommand
Dim rd As System.Data.OleDb.OleDbDataReader
Dim Conn As OleDbConnection

[code].....

View 1 Replies

Querying A Database Without Using Databinding?

Dec 24, 2009

I`d like to do a query to a SQL server database using the statements like "SELECT...FROM...." an so on. Then I`d like to save results of the query to an array or other variables. I`d like to handle the data of the query results "manually". I don`t want to use the datagridview and tableadapters and so on which are created when I drag a table from the datasources window to the form. is the ADO.NET and datasets the right tool at all? If yes, I believe these are the first steps needed:

- create a connection string
- create a connection and open it
- create a dataadabter
- create a dataset and populate it with the dataadabter

The first problem is the connection string. When I create a connection to a new data source in datasources window, a string is created and saved to some configuration file. Can I use it and how?

View 8 Replies

Querying A Sum() Value From Access Database?

Mar 15, 2012

Basically for normal select queries from my database I have no problems as I would put the following and then bind it to a controller to display the iteam, however now I am trying to query sum of a field from the database, but I think it should be different as It's giving a Nullable value:

SELECT SUM(PointsRedeemed) AS tAward
FROM [Transaction]
WHERE (BusinessId = ?) AND (CardNo = ?)

[Code]....

View 3 Replies







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