C# - Access Different Columns From LINQ Resultset?
Feb 26, 2011
I have a query which returns multiple columns from the database using LINQ
var donors = from d2 in db.Donors
where d2.Status == "Pending"
select new { donorID = d2.donorID, bloodGroup = d2.bloodGroup, contactNo = d2.contactMobile, status = d2.Status };
now I want to display the results in different Labels accessing one column value from donors resultset.
ex:
Label1.Text = donorID;
Label2.Text = bloodGroup; ...and so on
View 2 Replies
Similar Messages:
Jun 17, 2010
I have a situation where I am accessing a database multiple times and I'm wondering if it is necessary.
I have a GridView with a template column with a hyperlink to "Get Results" and on the RowDataBound event I have it check the batch number against the database and see if results exist and then if they don't, hide the link.
So when viewing the page if there is 20 rows in the gridview it is effectively doing 20 queries.
I was wondering if it is a better idea to query the database once with all "batches" and load it into a datatable, then on the RowDataBound event query the datatable. The only issue I see with this is there is currently 40,000 batches and grows daily.
View 1 Replies
Jan 30, 2010
I hava a textbox and button in my project. I want the button on click to add a new column inside the database "Trial.mdb" , table name "table1". The column name will be text typed in the textbox and it will be text type. How could I do that? with a sql code in asp:accessdatasource or in my code behind ?
View 13 Replies
Aug 17, 2010
I have a partitioned db where several tables have the exact same structure. I'm able to query the tables using linq, but only by quering the individual tables 1 at a time and by using the explicit table name. For example at the moment, I have 8 tables so I have something similar to the following:
[Code]....
Is there any way, that based on a certain value (stringValue), I could determine which table to query and then code the linq query just once?
View 2 Replies
Mar 23, 2011
I have two tables:
Entity
ID (PK), int
Name
Descrip
Users
ID (PK)
EntityID, int (this is not connected to Entity table)
Now I am using LINQ to pull the records which has a Entity.ID = something. Which will show me couple of records in my GridView. Here is my LINQ statement:
protected void Page_Load(object sender, EventArgs e)
{
string getEntity = Request.QueryString["EntityID"];
int getIntEntity = Int32.Parse(getEntity);
OISEntityTestingDataContext db = new OISEntityTestingDataContext();
//OISLinqtoSQLDataContext db = new OISLinqtoSQLDataContext();
var tr =
from r in db.Users
join s in db.Entities on r.UserID equals s.ID
where s.ID == getIntEntity
select new
{
//To Show Items in GridView!
};
GridView1.DataSource = tr;
GridView1.DataBind();
}
Now here I am getting an error mesg on 'join' The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join What does that mean?
View 3 Replies
Mar 10, 2011
I have two tables.[Table.Game] Columns are "PK_id" "username" and "couponID" [Table.Coupons] Columns are "PK_id" "CouponID" and "Points" The two columns "CouponID" are associated with eachother. Let say i have two rows with the user "harry" in [Table.Game] this person has two different couponID. In [Table.Coupons] this user "harry" has "CouponID" 1 and 2. Column "Points" have 10 and 20. To the question how do u sum this two different point values that have different "CouponIDs". This does work if i have only one "CouponId". But not when the user has 2 different CouponIDs. Values is 0
var points = (from p in linq.Coupons
join g in linq.games on p.couponID equals g.couponID
where g.username == username && g.couponID == p.couponID
select (int)p.win).Sum();
View 2 Replies
May 11, 2010
If I have a linq statement like:
[Code]....
There may be a lot of data in the Blogs table. What if all I wanted was say BlogID, BlogTitle and BlogAuthor and nothing else, is there a way to do this in an effort to make the sql more efficent?
Along the same lines in my DataContext (.dbml) file I added some associations between some of my tables. This makes coding nice when I do a linq statement that will join those tables automatically for me but my concern is does it do that everytime, thus making all my linq quieries inefficient?
View 1 Replies
Jul 17, 2010
I am trying to Fill my dropdownlist with two column as textfield and 1 column as value field.
dropdownlist2.items.add(new listitem(??? , ??? )
I used Foreach and many many options , I can assing the textfield easy but value I can't
Dim db1
As
New TripsLinqDataContextDim
listhotel = From th
In db1.Triphotels _
Where th.TripCountryID = cid _
Select
CStr(th.TripHotelID) +
" - " + th.City.TripCityName +
" - " + th.TripHotelName
ListBox1.DataSource = listhotel
ListBox1.DataBind()
This will list hotelname and id and city , but I need to set the Triphotelid as value of item in dropdownlist
View 1 Replies
May 8, 2010
how to write that below query in linq
DECLARE @Name varchar(20)
Select @Name = empFirstname+','+empLastName+','+empBankCode From srpEmployee
PRINT @Name
View 7 Replies
Apr 19, 2010
I have just started using LINQ with VS2008. I have added extra columns to my table, saved the changes, but class ClassName.Designer.CS didn't get updated. What do I have to do to updated the class? Do I have to do it manually, or is there a way to automatically synchronize tables and ClassName.Designer.CS?
View 2 Replies
Aug 3, 2010
I am using dynamic data entities linq to sql project. For my test project I have one table, with 10 columns and a single primary key for example. Almost all the columns are varchars.I can get the basic project up and running fine - update, delete, insert etc.ince it has no foreign keys, there are no search filters rendered. I was wondering if there was an easy way to generate a set of filters for the columns for this table. So a First name and last name search box. Is there a way to generate these filters for chosen columns and is there a way to generate these for all the columns
for example, above each of the columns in the grid there might be a text box ( I am not too fussed where the text boxes are rendered as such). Each of the text boxes will act as a filter for that column (doing a SQL 'like')
View 1 Replies
Jan 26, 2010
I have the following code:
[Code]....
With this code behind:
[Code]....
Initially, I wrote the GetTeamMember() method to display the FullName in the ItemTemplate.
Then as I wrote the EditTemplate, I needed to populate a DropDownList with a list of names (first and last). It was fairly easy using the LinqDataSource, however it currently only shows the LastName. I could write another method GetTeamMembers() to populate the ddlTeamMember with the data I want, but I thought maybe there's a better "LINQ" way.
So I'm looking for a better way to get FullName (i.e. Firstname + " " + LastName) into both lblTeamMember and ddlTeamMember.
Options I thought of are:
I could write a method GetTeamMembers() I write a StoredProc that returns the extra column Better way?
View 6 Replies
Oct 30, 2010
I need to know how to display the result of a select query in a datagrid or GridView with VB.NET?
Consider SELECT * FROM some_table. I don't know what columns the table has. Is there a way to just output the result to a table, with a dataset for example?
View 3 Replies
Sep 6, 2010
I want to combine two queries like :
select name as name1 from table1 where id = 6
and
select name as name2 from table1 where id = 2.
I need a single resultset. How can I do that?
View 26 Replies
Aug 24, 2010
I've a resultset that returns some 55 rows which is typically a dynamic query like [Select column_name from table_name where column = condition].
I need to execute this query which is in resultset and insert the value of column_name into another table.
I dont get the way as how to make it. Kindly suggest me as how can I execute it.
View 1 Replies
Sep 30, 2010
Is there a way to row two and three of the result set be returned so that the
following query:
[Code]....
View 10 Replies
Oct 5, 2010
Can we use different resultset in our Report. Like if we have written two select statement in our SP, how can we use the different result set to bind them in our Report.
View 3 Replies
Dec 26, 2010
i want to get first picture of any album in photo table. i want get output table for show to the datalist control.i need to get albumid in output
so i create a sproc similar this:
create PROC USP_GETFirstPhoto
@ALBUMID INT OUTPUT,
@CATEGORY NVARCHAR(50) OUTPUT ,
@CAPTION NVARCHAR(50) OUTPUT
AS
SELECT @ALBUMID = A.AlbumID,@CATEGORY=A.Category,@CAPTION=TMP.Caption FROM Albums A
CROSS APPLY
( SELECT top 1 * FROM Photos
WHERE AlbumID=A.AlbumID
)TMP
order by A.AlbumID
DECLARE @x INT,@y NVARCHAR(50),@z NVARCHAR(50)
EXEC USP_GETFirstPhoto @x output,@y output,@z output
select @x,@y,@z
but when i exec this proc i have a recorde not a result set
with this query i have resultset
SELECT * FROM Photos
CROSS APPLY (
SELECT TOP 1 AlbumID FROM Photos
GROUP BY AlbumID)TMP
View 16 Replies
May 17, 2010
I have a procedure that im going to be calling on my page load, i will pass an id to it and it will return up to 6 records. I need to set a session for each record returned.
Can i do that within my page_load event to pass the value, and set the sessions?
If no results are returned, then that session will be 0. So in other words, regardless there will always be 6 sessions that need to be set, either with the results returned or with 0.
View 22 Replies
Nov 10, 2010
I have the following query, the relationship is mutiple pictures per dog and multiple dogs per registered User. the query below will return dogs that belong to users that have not expired. the problem is that some users have many dogs and other users only have one dog listed, the query below will return a record for every dog. What I would like to do is return a random dog per user and only one dog per user each time the query executes. therefore if I have 10 users and 50 dogs I would like my quesry to only return 10 dogs one beloinging to each user, and the next time the quesry executes it would be nice if it once again return 10 dogs but a different 10 dogs 1/per user where it was able..
[Code]....
View 10 Replies
Mar 31, 2010
I have a table Structure
filename AKA
12-3-09.pdf 443567
12-3-09.pdf 345678
12-3-09.pdf 456789
3-3-10.pdf 78901
filename AKA
I want to output as 12-3-09.pdf 443567,345678,456789 3-3-10.pdf 78901.
View 20 Replies
Dec 26, 2010
is it possible to access grid column by name not by index grid.columns["name"] because if i add new column i must change all numbers
View 1 Replies
Mar 21, 2011
I have the default membership table that was added automatically, then just used server explorer to add more columns, like FirstName, LastName, etc. In my code I can access all the default columns, but not the ones I created. Any thing special I need to do?
Here is how I access the table. using user. gives me all columns, but the one I created.
string userName = User.Identity.Name;
MembershipUser user = (MembershipUser)System.Web.Security.Membership.GetUser(userName).ProviderUserKey;
View 2 Replies
Feb 16, 2010
I have a GridView :
[code]....
I want to query the value of a particular field in a DB and if it's true, display the LinkButton. if false, I want the linkButton not to be displayed.
is there a way to access the GridView programmatically and make visible certain of its columns or manipulate its items ?
View 2 Replies
May 8, 2010
I have a Access DB. I have relations with two tables. For example In my table1 I have three columns as T1ID, Name, Description and Tbale2 I have three column as T2ID, T1ID which is a foreignkey from Table1 and desc.
What I want is that : for example, I wanna copy the columns from table2 which has the value of 2 under the foreignkey field and I wanna insert them into table2 again with the value of 3 under the foreignkey field !
View 4 Replies