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
Similar Messages:
Aug 17, 2010
What is difference between select { } and select new {} In Linq Query
View 3 Replies
Mar 24, 2011
next code works with no problem at all but, isn't there a more elegant way?
What I want is to show all records when querystring is null and only those
who match the criteria when querystring is not null.
[Code]....
View 3 Replies
Feb 15, 2011
I have a class library which has my LINQ doc in it. I added a stored procedure and I get the following in my .dbml.layout :
[Code]....
I include a reference to the dll of the class library to my web project and I get an error about value being returned as int where I am trying to put contents into a datalist or similar.
Code in class that calls this SP :
[Code]....
So I switched code to the following in my dbml.layout document :
[Function(Name="dbo.sp_newsSearch")]public IEnumerable<news_search_result> sp_newsSearch([Parameter(DbType="VarChar(200)")] string searchVal){IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), searchVal);return ((IEnumerable<news_search_result>)(result.ReturnValue));}
And included the following in an external file news_search_result.cs
[Code]....
But now I just get nothing returned. Is this wrong way of calling a SP via LINQ? or have I just put the wrong return type on my LINQ class?
View 2 Replies
Jan 30, 2010
I have a requirement to convert LINQ to DataTable.
I stole the following Extension Method from StackOverflow:
[code]....
View 2 Replies
Aug 17, 2010
I have a linq to sql entity class in which I declared some DateTime fileds like this:
[Code]....
And this is how I fetch data form repository:
[Code]....
All non DateTime fields are filled properly but all datetimes are null.[Column(DbType = "smalldatetime")]
View 8 Replies
Feb 9, 2011
I'm having a spot of trouble figure out how to write my linq query so that is allows a decimal field in my datatable to be null
Right now I have this:
[Code]....
But it's not working. The error I am getting is: Cannot cast DBNull.Value to type 'System.Decimal'. Please use a nullable type.so how do I get it to allow program_ar_id to be null?
View 2 Replies
Mar 12, 2011
Right now I have an error if f.ParentID is null:
DataSet1.TreeItemRow[]
TreeItemRows = (from f
in tidt
where (f.ParentID == TreeItemId)
select f).ToArray();
I must continue if f.ParentID is null, I don't want to include null fileds in the array. What is the right syntax for that is linq sql?
View 17 Replies
Jan 14, 2010
I couldn't come up with a good subject. I have a simple ASP.NET 3.5 form. If you follow the numbered comments, I explain how I am stepping through the code when I run the page in debug mode. Both of the below functions are methods declared in the code behind file of the page, both are in the same _Default class. The ManagersListBox is declared in the Default.aspx page. Why is it that in the context of the GetSubordinates, the ManagersListBox is null? It's as if it disappears for a moment and then reappears after returning from the GetSubordinates method. Obviously the solution is to parameterize GetSuborindates, but that is not my concern. I am trying to learn how ASP.NET works and I would really like to understand why I am seeing this behavior "disappearing object".
[Code]....
View 1 Replies
Feb 3, 2011
I have stored procedure which selects records from an SQL table based on a bunch of user-input parameters.Just discovered that if a record in the table has null values in some of the columns (I haven't figured out which ones yet), then the SELECT is not returning the record (even if it satisfies all the parameters).The SELECT statement is supposed to allow for nulls, and I've been over it a bunch of times and am not sure what I'm doing wrong.Or do I need to get rid of all the null values in the SQL table, and prevent new ones from being introduced?
[Code]....
View 6 Replies
Aug 27, 2010
I am converting my datatable to LISt using LINQ how do I handle nulls coming from database
List<Port> portDetails = new List<Port>();
DataTable dt = ds.Tables[0];
portDetails = (from q in dt.AsEnumerable()
select new Port
{
PortCode = q.Field<string>("Code"),
ExtCode = q.Field<string>("Nb"),
Name = q.Field<string>("Name"))
}).ToList();
In the above query if Code is null I do not want property portcode to be set to the value it should only set if it is not null or not blank
PortCode = q.Field<string>("Code"),
What should be syntax
I was trying somethign like this which doesnt work
Portcode = q.Field<bool>("Code") == null ? null : q.Field<bool>("Code")
View 1 Replies
Mar 31, 2010
I have a SP db.sp_GetProfitMatrix , it takes nullable integer parameters, for which I have a default . It refuses me when I try to pass a null value (the two date parameters are nullable in the Linq designer) I get {"Nullable object must have a value."} error. here is my code:
int? nlDt = null;
var pms =
from p
in db.sp_GetProfitMatrix( nlDt.Value, nlDt.Value)
select
new
{
p.Volume,
p.GrossSales,
p.NetSales,
p.COGS
};
View 4 Replies
Dec 15, 2010
Using linq to entities i am connecting to a database, the database has tables in it that has payments that have a multi to multi relationship with jobs. This is acheived via an allocs table. I want a list box with all the jobs that has a column called due price which takes all of the allocations of payments for this job and takes that away from the job price. However, using the below linq to entities statement. The problem is that if the job has no allocations it returns null and therefore the due payment is empty. What i really want is for the due payment to be the job price if there are no allocations however, i cannot think of a way around this.
var jobs = from j in data.jobs
where j.property.customer.id == customerid
&& j.completed != null
select new
{
j.id,
j.price,
dueprice = j.price - ( from a in data.allocs
where a.job.id == j.id
select a.amount ).Sum(),
lineone = j.property.lineone,
postcode = j.property.postcode,
jobtype = j.jobtype.name,
j.completed
};
View 3 Replies
Apr 7, 2010
I'm using LINQ together with XDocument to read a XML File. This is the code:XDocument xml = XDocument.Load(filename);
var q = from b in xml.Descendants("product")
select new
{
[code]...
View 3 Replies
Feb 27, 2011
I am trying to pad for null values in the below code. Anybody know how to fix this error? Conversion from type 'DBNull' to type 'String' is not valid.
Dim dvUserImgPath As Data.DataView = CType(ImgPathDS.Select(DataSourceSelectArguments.Empty), Data.DataView)
Dim drUserImgPath As Data.DataRowView = dvUserImgPath.Item(0)
lblHiddenImgPath.Text = drUserImgPath.Item("ImgPath")
View 5 Replies
Aug 26, 2010
why use where condition before select statement in LINQ
View 2 Replies
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
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
Jan 19, 2011
How to make the linq throw error, when not null columns are there in the table.
Why I am saying, it is. I tried to add to column in the table. Linq throwed error os some sort. I could not understand. it was like some innner table etc.
I had to resort to native sql, which showed the error, as the not null fields are there in the table.
View 5 Replies
Jan 4, 2010
If the datavalue which is empty and not exist in the dropdownlist data source, it will prompt error. How to overcome??I want it will show 'Select Country' when data value is empty or is null.
<asp:DropDownList ID = "ddllabelCountry"
DataSourceID="objCountry"
DataTextField="CountryName"
DataValueField="CountryCode"
EnableViewState="true"
[code]...
View 7 Replies
Jun 9, 2010
if a person does not select image in website in database null value go. when we retrieve data for that person i want if image is null then i want to show blank face image. for storing and retrieve image im using handler.ashx but not able to do the part that i have explained .
View 7 Replies
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
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
Aug 4, 2010
Using a ListBox, where multiple items can be selected. Using StringSplit SQL function the string passed from Listbox is separated where the delimeter is comma ( , ).ListBox is in search form where user enters search criteria using other controls and the ListBox. All works good by simply using below SQL statement in Stored procedure that carries search.
[Code]....
Question:- Now one of List Item is None , when None is selected or None is selected with other ListItems from ListBox it is required to retrieve all records where COLUMN IS NULL.Example: When the Male, Female and None is selected from ListBox, SQL statement in Stored procedure will be
[Code]....
Like to know how this can be handled? It is required to retrive NULL values when None is selected in ListBox as well as in combination of other ListItems(Male and Female) i.e., Male, Female, Null when user selects multiple items from ListBox.
View 2 Replies
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