C# - Use Linq To Sql To Select One Column From Row?

Dec 18, 2010

I am using this C# with linq to sql:

string currentLabel = from s2f in stream2FieldTypesTable
where s2f.s2fID == item.s2fID
&& (s2f.s2fLabel != item.s2fLabel || s2f.s2fIsRequired != item.s2fIsRequired)
select s2f.s2fLabel;

I am getting a compiler error saying i can't assign type System.Linq.IQueryable<string> to string.

I tried this code:

string currentLabel = from s2f in stream2FieldTypesTable
where s2f.s2fID == item.s2fID
&& (s2f.s2fLabel != item.s2fLabel || s2f.s2fIsRequired != item.s2fIsRequired)
select s2f.s2fLabel.ToString();

And that returns the same error. I'm sure this is a simple thing. what am I missing? I just want the first s2fLabel that matches the where clause.

View 4 Replies


Similar Messages:

DataSource Controls :: LINQ - Select Column In Data Table?

Feb 9, 2010

Mmy data table has four columns. How can I get only selected columns name?

View 5 Replies

DataSource Controls :: Create A Multi Column Listbox By Combining Fields In Linq Select Statement

Jan 11, 2010

I am trying to create a multi column listbox by combining fields in Linq select statement, as Let Name = Last + First. The problem is how to pad the Last column with spaces as you would in SQL using REPLICATE so when I bind the listbox to the data, it looks like two columns.

View 5 Replies

ADO.NET :: Difference Between Select And Select New In Linq Query

Aug 17, 2010

What is difference between select { } and select new {} In Linq Query

View 3 Replies

Forms Data Controls :: How To Add A Column Header To A Column Of Auto Generated Select Buttons

Aug 18, 2010

I have a gridview which has a column of auto generated select buttons, where a user can select a row.However, I would like to add a column header to my auto generated select buttons in order to make the gridview look complete, but I am unable to see how I can do this. Does anyone know how I can add a header text to an auto generated select button?

View 2 Replies

DataSource Controls :: How To Select Column Value From Grid And Hide A Column

Oct 19, 2010

I'm trying to retreive a column value from gridview5 to use it in a query to display resuls in gridview, Also how do you hide a column in the grid?

Where (p.Link_ID Like GridView5.?

[code]....

View 3 Replies

ADO.NET :: Using Where Clause Before Select In LINQ?

Aug 26, 2010

why use where condition before select statement in LINQ

View 2 Replies

C# - LINQ To SQL Dynamic Select?

Jun 7, 2010

how to indicate which columns I would like returned at run-time from a LINQ To SQL statement?I am allowing the user to select items in a checkboxlist representing the columns they would like displayed in a gridview that is bound to the results of a L2S query.I am able to dynamically generate the WHERE clause but am unable to do the same with the SELECT piece. Here is a sample:

var query = from log in context.Logs select log;
query = query.Where(Log => Log.Timestamp > CustomReport.ReportDateStart);
query = query.Where(Log => Log.Timestamp < CustomReport.ReportDateEnd);

[code]...

View 2 Replies

ADO.NET :: Linq Select Null Value?

Oct 7, 2010

[Code]....

[Code]....

I have to get the maximum of these two select values. The select values are nullable. How do I go about checking if the value is null before calling the Max() method on it? I tried the ?? coalesing operator (example: e.HomeSales.Max() ?? 0M,) but I get the following error:"Operator '??' cannot be applied to operands of type 'decimal' and 'decimal'"

View 2 Replies

ADO.NET :: Linq To Sql Select Table At Runtime

Mar 15, 2011

I have several tables to load from depending on a string value using Linq to Sql I currently have

[Code]....

but of course that only gets the specific table DOffices if I wanted to grab tables at runtime what would be the best way to go about it?

View 1 Replies

ADO.NET :: Select Using Stored Procedure In Linq To Sql?

Jan 30, 2011

i am using stored proc in linq to sql but i have done insert & delete operations but im unable to do the select operation i have tried but no use,whenever i enter the id into the textbox it should display the record?

View 5 Replies

ADO.NET :: Select Name Column From The Applicant Table And Value Column From ApplicantValue Table?

Feb 2, 2011

I am quite new to LINQ, and I am stuck with this probably basic problem, but haven't been able to find a solution, so I thought I could ask here.

So, I have this repository where I put my functions for data accessing, and now I need to write a function to get all the applicants that have applied for this particular advertisement, and their values too. Now, the values are stored in a separate M:N table, where every row consists of the applicantID,advertisementID and value. I just wanna append the value to every applicant that I show, so that it would look like a Ranking List.

However, I do not seem to know how to select just the name column from the Applicant table, and just the Value column from the ApplicantValue table.

And there's this Iqueryable interface that further confuses me...

Here's my function to get the Applicants only:

[Code]....

Now, if I try to add to the definition of the type two columns, it says that it only messes with types, i.e. one type should be passed. So I figured I would do a ViewModel and then pass it, like this

[Code]....

and then in the function I have no idea how to pass the values:

View 5 Replies

C# - Delaying Linq To SQL Select Query Execution

Jun 14, 2010

I'm building an ASP.NET MVC site that uses LINQ to SQL. In my search method that has some required and some optional parameters, I want to build a LINQ query while testing for the existence of those optional parameters.

Here's what I'm currently thinking:
using(var db = new DBDataContext())
{
IQueryable<Listing> query = null;
//Handle required parameter
query = db.Listings.Where(l => l.Lat >= form.bounds.extent1.latitude && l.Lat <= form.bounds.extent2.latitude);
//Handle optional parameter
if (numStars != null)
query = query.Where(l => l.Stars == (int)numStars);
//Other parameters...
//Execute query (does this happen here?)
var result = query.ToList();
//Process query...

Will this implementation "bundle" the where clauses and then execute the bundled query? If not, how should I implement this feature?

View 1 Replies

ADO.NET :: Use Of PATINDEX Function In Select Clause With Linq?

Sep 6, 2010

i have an problem to use of PATINDEX function in select clause with Linq.

View 1 Replies

DataSource Controls :: How To Select Only Certain Columns With LINQ

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

ADO.NET :: LINQ If Statement Inside Select New Query?

Aug 18, 2010

My application includes BUILDING table with columns BUILDING_ID, NAME, TOWN_ID, I run the LINQ query listed below and need to append two letters to buildings.NAME based on TOWN_ID. I assume that I need to place an "if" or "select" statement inside the query but I can not figure out how to do that,

[Code]....

View 4 Replies

C# - Linq: Select First Items From The Child List?

Jun 24, 2010

I have the following one-to-many relation between two objects.

Parent
--> IList<Child>

Now, I have a List of Parent objects and I want the First Child of each parent in the list.

What is the best way to do this using Linq?

View 3 Replies

C# - Select Width Entity Framework And Linq?

May 17, 2010

i have 2 table missions and missiondays with a relationship 1..n

I want select all missions that has all missiondays with an attribute called "visible" = true

I've tried with:

db.TDP_Missioni.Include("TDP_MissioniDestinazioni").where(p => p.TDP_MissioniDestinazioni.visible == true)

But there is an error. Indeed from p.TDP_MissioniDestinazioni i don't see the table's attributes. I think it's because the relationship is 1..n.

View 2 Replies

ADO.NET :: Linq To Entities: Always Select Before Delete And Update?

Sep 21, 2010

With linq to entities, how can I delete and update data inside a database without first selecting the complete entity at first?

View 4 Replies

MVC :: Get Column Of A Table Using Linq?

Feb 2, 2010

In my application i want to compare data of two users from database table using linq.

lets say i have ten columns in UserMaster table.

Now based on the comparision i want to display result.

Like is 10 out of 10 columns matches for those two users result will be 100,if 9 columns matches then result will be 90 and if 0 matches thn result will be 0.

i dont want to write if else for somany time.

I am new to linq.

View 4 Replies

ADO.NET ::calculate A New Column IN In Linq?

Aug 12, 2010

I would like to select some data from multiple tables and calculate a new column IN the query.In SQL it would look like: (select A, B, ((C * D) + (C * E)) as 'calc' from tab1 join tab2 on.join tab3 on.join tab4 on ...);I've tried this in linq, but it didn't work as I believe.

[Code]...

View 3 Replies

C# - SQL Group By Column Value In LINQ?

Jun 25, 2010

I am trying to translate this:

SELECT IDNum, Max(Convert(varchar(20), (TimeOut - TimeIn), 108))
FROM IO_Times Group by IDNum
order by Max(Convert(varchar(20), (TimeOut - TimeIn), 108)) desc";

Into LINQ in C#. The above returns a list of the maximum value of (TimeOut-TimeIn) that corresponds to each unique IDNum (There are multiple TimeOut-TimeIn values for every IDNum).Here is what I am trying now:

from IO_Time in db.IO_Times
orderby SqlMethods.DateDiffMinute(IO_Time.TimeIn, IO_Time.TimeOut) descending
group IO_Time by IO_Time.IDNum into list
select new
{
ID = list.Key,
Time = list
});

This returns the correct IDs in the correct order, but the "list" contains everything in the database entry (which makes sense). I have also tried group by IDNum and Time, but then I get unique time entries and multiple IDs returned.I could do a foreach loop and manually sort it all out, but I would really rather not do that.

View 2 Replies

DataSource Controls :: How To Select Data With Linq And Bind To A DDL

Jan 5, 2010

I am trying to select data with Linq and bind to a DDL. The custid field allows duplicates in this table, but I only want unique values in the ddl. I tried the following code:

[Code]....

The use of "Select Customer.CustID", with or without the Distinct, causes this runtime error. CustID is a valid field in the table, and it shows up in intellinsense and compiles. If I just Select Customer, the error goes away, but Distinct doesn't know to look for distinct custid's.

DataBinding: 'System.String' does not contain a property with the name 'CustID'.

View 2 Replies

ADO.NET :: Insert And Select Data From Stored Procedure Using Linq?

Jan 18, 2011

i do have a stored procedure which inserts data and the message should be displayed that data has been sucessfully updated or not

[code]....

View 8 Replies

Select Query In LINQ Based On Foreign Table

Mar 2, 2011

I have 2 Tables , OrderDetails and Requests In my LINQ to SQL dbml file. OrderDetailsID is a foreign key in Requests Table. I want to write the query to get the sum of UnitCost from OrderDetails based on OrderId. And If there is a row in Requests Table for each OrderDetailsID, and the Requests.Last.RequestType="Refund" I want to reduce the total refund amount from the main sum otherwise If there is no row based on OrderDetailsID, add to sum. Here is the way I implement that. I am looking to prevent using "For each".

iRefund = (From od1 In dc.OrderDetails _
Where od1.OrderID =1 _
Select od1.UnitCost).Sum
Dim objOrderDetails = (From od1 In dc.OrderDetails _
Where od1.OrderID =1 _
Select od1)
For Each OrderDetail As ORM.Entities.OrderDetail In objOrderDetails
If Not OrderDetail.Requests Is Nothing Then
IF OrderDetail.Requests.Last.RequestType="Refund" Then
iRefund -= OrderDetail.UnitCost
End If
End If
Next

View 1 Replies







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