DataSource Controls :: Random Results From A LINQ To SQL Query?

Jan 23, 2010

I have this LINQ query:

var agnts = (from a in db.agents select new { a.userid, a.name }).Take(10);

How can I get randomly get 10 records from my agents table?

I have tried:

agnts = agnts.OrderBy(n => Guid.NewGuid());

but this doesn't seem to do anything.

View 5 Replies


Similar Messages:

ADO.NET :: Build A Linq Query / Linq Random Selection?

Sep 14, 2010

I've build a linq query.But i want a random selection so its not always ID : 1,2,3,4,5,6 How can i randomize this var? I like to bind it to a repeater.//TagCloud:

Random rand = new Random();
var tc1 = from i in JumpTide.cms.menu.GetMenuItems(32)
select new

[code]...

View 1 Replies

DataSource Controls :: Validate Results Of A Query?

Jun 17, 2010

I am trying to find out if there are records in a table

based on the results of the query.

I have this that is not working

The query works but the problem is validating the resutls

MembershipUser myUser = Membership.GetUser();
Guid userIdPosts = (Guid)myUser.ProviderUserKey;
int currentThreadid = Convert.ToInt32(Request.QueryString["Threadid"]);
var query = from t in context.TrackLists
where t.UserId == userIdPosts && t.ThreadID == currentThreadid
select new { t.UserId, t.ThreadID };
foreach (var results in query)
{
Guid queryUserID = results.UserId;
}
if (queryUserID == null)
{
}

View 2 Replies

DataSource Controls :: Passing Results / Parameters In LINQ

Jan 20, 2010

im new to linq and im having lots of trouble creating complex queries.. My problem mainly is that i am using Linq as a BLL.

i created a dbml (with namespace called DAL) file with 2 tables with a one to many relation. Pop and City. There is a forgien key in pop that points to a city. I also created a class called Pop that inhertis DAL.Pop. Now in my ASPX page, i want to call a function in the Pop class that would retrieve some Pop according to its ID, but i need the city name as well.. Ive been going around this in circles for days. I dont know how to write the Linq syntax and i dont understandd how my function's signature should be like.. I want to recieve a table that i can bind to a Gridview and preferable, specify which coloumns to bind.

View 2 Replies

LINQ-to-SQL Query Returning No Results?

Mar 5, 2011

I have a query using LINQ-to-SQL. It queries an underlying database table Rooms. It uses Where conditions to narrow down the results, namely:

Gender.
Current Occupancy < Max Occupancy
Available Flag is Checked

I know this should return results but it keeps returning an empty set. Any ideas? Code is below

Dim selectedHalls = (From sh In dbHalls.Rooms _
Where sh.gender = Session("gender").ToString _
Where sh.max_occupancy > sh.current_occupancy _
Where sh.is_available = 1 _
Select sh.building_name).Distinct()

UPDATE: I've verified that the issue is with the statement where sh.is_available = 1, which doesn't make sense since this is a bit field.

View 3 Replies

ADO.NET :: How To Alphabetise The Results From A Linq To Sql Query

Jan 26, 2011

I can't seem to change the order of the results coming back from a linq to sql query, I want just to return the distinct values from the field x.manufacturer in alphabetical order, this is what I have and it isn't working:

public IQueryable<string> Dropone()
{
return (from x in CAT.CatalogueDatas
where x.Parent == null
orderby x.Manufacturer
select x.Manufacturer).Distinct();
}

Currently I get the distinct values in non-alphabetical order, in fact I'm not sure what order they're coming out in, don't think it's the order in which they appear though.

View 5 Replies

DataSource Controls :: Showing Query Results In A Textbox?

Jan 8, 2010

Lets say I had a query like SELECT Name FROM Customers WHERE CustomerID = '1'

How could I show the result in a textbox?

View 3 Replies

DataSource Controls :: Email Query Results Formatting?

Feb 25, 2010

I have a SQL server job that executes msdb.dbo.sp_send_dbmail procedure and sends an email. I have specified the query and the query results appear in the body of the email as expected. All i need to know is how to remove the dashes beneath the column names. For instance, when I receive the email with the query results, they look like the following

UserId UserName

1 Rob
2 Paul

How do I remove those dashes underneath the column names?

View 3 Replies

DataSource Controls :: Writing A Query Filter That Gets All Results For That Day?

May 11, 2010

i have a "Users today" function that i am trying to work on, i have all the tables set up, and a TimeStamp column, i would like to know how i could get all the users that appeared, but for that day only.

So i used the select statement, but then when i tried to add into query, filtering, i tried using the DateTime.Now, but it only got the users specific to that date, hour, and second.

View 3 Replies

DataSource Controls :: How To Convert Sql Query Into Linq Query

Mar 10, 2010

select Groupid,GroupName,onorusername from palgroup where groupid in (select distinct Groupid

View 5 Replies

DataSource Controls :: Linq To SQL Return All Results / Wild Sign?

Feb 2, 2010

I've been reading around, and it sounds like this is somewhat common, though I'm missing something.

I have my filtering rerouted to my codebehind via DataGridSource_Selecting event handler per

http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx

I have a set of controls on my page, Start Date, End Date, User, Status

Start and End Date are expected to always contain a value

User and Status I want to also have an 'All' option, where in it would return all results/not filter.

One method I can think of using for this, is the put the queries in a If scenario, where

if(user == All), use linq query B
if(user != All), user linq query A

where linq query A contains the filtering on Users, and linq query B does not.

What I have so far is

[Code]....

What I need

[Code]....

where User == ??,

can the control that populates that contain a wild card option as well? ie *, so that if user == Name, it filters on Name, or if user == *, it returns all?

View 2 Replies

DataSource Controls :: LINQ To SQL - Multiple Queries Doesn't Return Any Results

May 25, 2010

I am working on asp.net 3.5 and in MVC using Linq to SQL classes. In my MVC project i am calling stored procedure using linq to sql that conatin query joining two tables.Below is my code in Partial class

[
Function(Name="dbo.GetUserWiseThreadDetail_SP")]
[ResultType(typeof(Thread))]
[ResultType(typeof(Reply))]
public
IMultipleResults GetUserWiseThreadDetail_SP([Parameter(DbType="VarChar(30)")]
string userID)
{
ExecuteResult result = this.ExecuteMethodCall(this,
(MethodInfo)(MethodInfo.GetCurrentMethod())), userID);
return ((IMultipleResults)(result.ReturnValue));
}

In one of the controller i have made one more class

public class
MypostIndexData
{
public
IEnumerable<Thread> Thrds {
get;
set; }
public
IEnumerable<Reply> Repls {
get;
set; }
public MypostIndexData(IEnumerable<Thread>
thrds,IEnumerable<Reply> repls)
{
this.Thrds=thrds;this.Repls=repls;
}
}

finally coding of controller action method

ForumDataContext pmforum = new
PMForumDataContext();
public
ActionResult MyPosts(string userId)
{
IEnumerable<Thread>thrds;
IEnumerable<Reply>repls;
IMultipleResults result = pmforum.GetUserWiseThreadDetail_SP(userId); (this satement doesnot give any result,if i execute stored proc in
sql it give the results)
thrds = result.GetResult<Thread>();
List<Thread> thrdlist =
new
List<Thread>(thrds);
repls = result.GetResult<Reply>();
List<Reply> replylist;
if (repls !=
null)
{
replylist = new
List<Reply>(repls);
}
return View(new
MypostIndexData(thrds,repls));

I am unable to understand why i am not getting any results?

View 5 Replies

DataSource Controls :: Combine The LINQ Queries Together And Have Access To Both Of The Results Independently?

Feb 25, 2010

Is there a way to combine the LINQ queries together and have access to both of the results independently?

[Code]....

View 10 Replies

VS 2010 - Can't Get Linq Query To Return Expected Results

Feb 13, 2014

I have a array list and am using like a database trying to search for ChildID and ParentID based on certain criteria.

My example below has the following keywords to search for:

Yellow, Mustard, Honey, Orange, Flame, Talisman

I also have a category volume value which I grab the first 2 characters to determine another filter.

My code isn't returning all matches with using 'Contains'. Right now it finds the 'Orange, Flame, Talisman'/AV record and returns 50, 28. My keywords also has 'Yellow, Mustard, Honey'/AV which should return 55 and 28 as well.

HTML Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="temp2.aspx.vb" Inherits="temp2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

[Code] ....

View 4 Replies

Web Forms :: Select CheckBoxList Items Based On LINQ Query Results

Apr 29, 2010

[Code]....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace find.Admin
{
public partial
class WebForm1 : System.Web.UI.Page
{
private
class servicetimeofday
{
public int servicetimeofdayid {
get; set; }
public int serviceid {
get; set; }
public int timeofdayid {
get; set; }
}
protected void Page_Load(object sender,
EventArgs e
{
List<servicetimeofday> servicetimesofday =
new
List<servicetimeofday>
{
new servicetimeofday() { servicetimeofdayid = 1, serviceid = 1, timeofdayid = 1 },
new servicetimeofday() { servicetimeofdayid = 2, serviceid = 1, timeofdayid = 2 },
new servicetimeofday() { servicetimeofdayid = 3, serviceid = 2, timeofdayid = 1 },
new servicetimeofday() { servicetimeofdayid = 4, serviceid = 2, timeofdayid = 3 }
};
GridView2.DataSource = servicetimesofday;
GridView2.DataBind();
var itemstocheck = from
servicetimeofday in servicetimesofday
where servicetimeofday.serviceid == 2
select ne
servicetimeofday.timeofdayid
};
GridView3.DataSource = itemstocheck;
GridView3.DataBind();
foreach (var timeofdayid
in itemstocheck)
{
foreach (ListItem i
in CheckBoxList2.Items)
{
if (i.Value == timeofdayid.ToString())
{ i.Selected =
true; }
}
}
}
}
}

View 10 Replies

DataSource Controls :: Creating Join Query / How To Address The Results To Be Stored Within The Output Variables

Apr 8, 2010

[Code]....

Well I'm not familiar with SP's yet, and I can't find a single example of what I want to do. basically I want to retrieve the town & county where the customers id are equal (note there will only ever be 1 result)

I can't figure out how to address the results to be stored within the output variables.

View 2 Replies

Forms Data Controls :: Prev And Next On Random Results

May 22, 2010

I have a SqlDataSource that pulls data from a table randomly. When I get this data in a formview, i want to be able to page through it (< prev next >) in that random order. Make sense? So in other words, whenever the query is run, I want it to pull a list from a table in a random order (which I've already got). I just want to be able to click next and prev within that random order?

View 2 Replies

DataSource Controls :: Query Using Linq To Sql?

Jun 25, 2010

I´m using Linq to Sql in my asp.net application, but the problem is:I have a query like this:

[Code]....

My query is not returning anything, how do I do to get this?my problem is with this interval I need to have.

View 2 Replies

DataSource Controls :: One Linq Query With Two Db Connection?

May 31, 2010

I want to use from two db connection in one linq query

My sample is:

int a=1;
if(a==1)
DataClasses1DataContext1 db = new DataClasses1DataContext1();
else
DataClasses1DataContext2 db = new DataClasses1DataContext2();
var q =
from c
in db.F_Groups
select c;

In this code a=1 so db connection is DataClasses1DataContext1

I want if a=2 then db connection = DataClasses1DataContext2

but this code is error.

db connections is completely same but in two deferent class a db connection is sql and another is oracle

View 4 Replies

DataSource Controls :: How To Convert Sql Query To LINQ

Feb 13, 2010

How can I convert this sql query to LINQ ?

[code]...

View 1 Replies

DataSource Controls :: Linq To Sql Query / Zip Codes?

Feb 18, 2010

Im doing thing profile, zip code thing on my site. One table has a list of zipcodes and in the other is a profile and there they keep what zip code they entered. I already have the radius code but idk how to get a list of all the profiles in a radius.I'm going to store the zip codes that come back from the zip code table in a arraylist and put it in a session state so i don't have to keep getting the same thing over and over again. The problem is i don't know how to write the linq to sql query to take the arraylist of zip codes and look up all the users that have that as there set zip code in there profile.

View 1 Replies

DataSource Controls :: Return First Value From A Linq Query?

Mar 12, 2010

Is there a way opf getting the first value from a linq query so for example

[Code]....

View 2 Replies

DataSource Controls :: Add A New Item To A LINQ Query?

May 13, 2010

So I'm trying to add a single item to a query I wrote. The query is then pass to the e.Result of a LinqDataSource_Selecting event. This datasource is being used by a dropdown list and label in a listview.

I am trying to add a "New" field to the end of the list.

Currently I have this working, but it seems like a really messy solution. First I make a class with the fields I need:

[Code]....

Then I build the query:

[Code]....

Then a second list and query with the new value:

[Code]....

Finally, I union the two and set the e.Result:

[Code]....

View 5 Replies

DataSource Controls :: Retrieve Value From LINQ Query?

Mar 20, 2010

I need to know how to extract the result of the attempted LINQ query below and set it equal to the strFile variable.Everything Intellisensed OK here but ine 5 shows a syntax error at the parenthesis.

[Code]....

View 12 Replies

DataSource Controls :: Linq Query With OrElse?

Apr 7, 2010

I'm having a problem with a Linq query where is executing the second half of an OrElse even though the first half evaluates to true.

[Code]....

When Manufacturer is null, I get a NullReferenceException. The "Manufacturer.Trim()" should never be executed, because the first half of the OrElse evaluates to true. Just to test it out, I also tried this:

[Code]....

This actually works fine... Manufacturer.Trim() is never executed, and I get no error. Why is the Trim() statement being executed in the first case? If Manufacturer is null, then it shouldn't be.

View 4 Replies







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