.net - Linq To SQL For Getdate() And Dateadd()?

Nov 10, 2010

The result will be '2010' for this query select year(getdate())

How do I get same result as Linq?select year(dateadd(yy,-1,getdate())), year(getdate()),

View 1 Replies


ADVERTISEMENT

Convert DateAdd (dd, - Day(getdate()),getdate()) To .net?

Mar 14, 2012

SQL - DateAdd(dd, - day(getdate()),getdate())

need to convert this into VB.net

View 3 Replies

Using Getdate() In Select Statement?

Feb 22, 2012

I am using vb.net 2005. I am trying to select data from a table where the field [hoteldate] is 2 days from now. The field's format is MM/dd/YYYY and when I use the Where clause :WHERE HOTELDATE = DATEADD([DAY], 2, GETDATE()) it returns nothing. I am assuming it's because the getdate() function returns something like 2012-24-02 T blah blah. How do I convert so I can get a match? I've tried several things including converting do a

View 4 Replies

Asp.net - SQLServer INSERT Getdate() Function Using Parameters?

Jul 8, 2011

What is the preferred method of adding the current date/time into an SQL Server table with INSERT Command and executenonquery? I'm expecting something like ...

cmd.Parameters.Add("@theDate", SqlDbType.VarChar, 20)
cmd.Parameters("@theDate").Value = "getdate()"

View 5 Replies

.net - Datediff And Dateadd Function?

Feb 22, 2011

If DateDiff(DateInterval.Day, moDoBooking.m_CurrentDay, moDoBooking.m_BaseDay) _
> DateDiff(DateInterval.Day, DateAdd(DateInterval.Day, _
Convert.ToDouble(moDoBooking.oBooking.oFacility.ADAYS), moDoBooking.m_BaseDay), _
moDoBooking.m_BaseDay) Then

This condition won't satisfy with these values:

moDobooking.m_CurrentDay = 2/3/2011
moDobooking.m_BaseDay = 22/02/2011
moDoBooking.oBooking.oFacility.ADAYS = 1

You might say this is dead-easy but honestly it's late here and my head is not working at all! Could AnyOne tell me why is that?

View 2 Replies

VS 2010 - Any Way To Add Milliseconds In DateAdd?

Feb 25, 2011

Is there a way to add milliseconds in dateadd? It is not in the DateInterval enum. I created a class so my program knows what the real time is, based off the sql server. This way, we don't have to worry about people's computer clock being off, or different time zones, etc. When the program starts, it grabs the current time on the SQL server, and starts a Stopwatch. Then each time I need the time, I find the elapsed time on the stopwatch and add to the SQL time. The problem is that I use these times sometimes to do timestamps as a unique ID for certain records, and sometimes multiple records get created in the same procedure, so it is being called more than once per second, so the same ID is returned. I need the time to go down to milliseconds, so it is more precise. Therefore, I can't just multiply the seconds by 1000.

Here's my class
vb.net
Public Class RealTime
'Added 11/03/2010 v0.4.4 To determine the real time, not the time on the local machine.
'The time will be stored in GMT +/-0 World Time
Private stopW As New System.Diagnostics.Stopwatch
Private StartTime As DateTime
[Code] .....

View 3 Replies

.NET Equivelant For DateDiff, DateAdd And Weekday Functions?

May 16, 2010

I know I can import Microsoft.Visualbasic and just use the ones I used in vb6. But I don't want to ;)In vb6 DateDiff("d", dte1, dte2) would just give me the number of days between the 2 dates and it didn't matter which order I put the 2 dates, it would still return x days.In .Net i have Date.Compare(dte1, dte2) but I have to know which date is newer other wise I get a negative result because I subtracted a bigger from the smallerIs there no .NET way to just get the difference without having to subtract then multiply by -1 if its less than 0?ALSO,In vb6 I could use Weekday function to get what day of the week a date is and use it in the DateAdd function to find the first day of the week's date. Like so: dim firstday as date = DateAdd("d", (Weekday(today, vbWednesday) - 1) * -1, today) would like a .Net way to find the date of the first day of the week, giving that our week might not start on sunday or even monday. I need to pass a date and the weekstart day (wednesday) and have it return the date for the wednesday. Like this:dim firstday as date = GetFirstDay(Today, Firstday.Wednesday)so if the date i passed was "9/3/10" which is a friday, the function would return "9/1/10" which is the date my week started on.

View 2 Replies

.net - Calculate A New Date Simply By Using The Build-in Dateadd Function?

Oct 14, 2009

I would like to calculate a new date simply by using the build-in dateadd function, but take into account that only weekdays should be counted (or 'business days' so to speak).I have come up with this simple algorithm, which does not bother about holidays and such. I have tested this with some simple dates, but would like some input if this can be done in better ways.This sample assumes a week with 5 business days, monday-friday, where first day of the week is monday. Dateformatting used here is d-m-yyyy, the sample calculates with a startdate of october 1, 2009.

Here is the simple form:

Dim d_StartDate As DateTime = "1-10-2009"
Dim i_NumberOfDays As Integer = 12
Dim i_CalculateNumberOfDays As Integer

[code]....

View 3 Replies

DateAdd Function - Arithmetic Operation Resulted In Overflow

Jun 15, 2010

I am using the following code to add some value to a date:
Dim strdate As Date
Dim numinterval As Double
numinterval = 149548.720386359
strdate = DateAdd(DateInterval.day, numinterval, #1/1/1601#)
MsgBox(strdate)

The value numinterval is the number of days passed since 1/1/1601 (this is how date is counted for things like 'last logon time', 'last bad password' in Active directory). I do some calculation and get that numinterval value in days.. But since I want it to return the time more accurately, I tried first multiplying numinterval by 1400 for number of minutes.. And I changed the interval as dateinterval.minute... That worked fine!

But, when I tried again by multiplying it further by 60, to get the time accurately in seconds and changed the interval to dateinterval.second it throws the following exception:
Arithmetic operation resulted in an overflow
I changed the type of numinterval into long, but the same problem..

View 2 Replies

Use Dateadd Function To Calculate Resumption Date Excluding Weekends?

Sep 16, 2010

I am trying to compute time off, I have a datetimepicker which allow user to select a day he wishes to start leave and a textbox to specify no of days applying for.Now I wand to use dateadd function to calculate resumption date excluding Weekends.

View 2 Replies

.net - ActiveRecord Linq/NHibernate Linq Not Building Query Completely?

Jul 14, 2011

given this function:

Public Function Search(ByVal StartIndex As Integer, _
ByVal MaxResults As Integer, _
ByVal AccountNumber As String, _
ByVal LastName As String, _

[Code]....

instead of what I expected:

Select count(*) from remitline where lastname = "smith"

What am I doing wrong building up the where clause? I'm using Castle ActiveRecord 2.1

View 1 Replies

Performance Gain In LINQ Query Vs LINQ Stored Procedure?

Aug 6, 2009

if there is that much of a performance gain in running a LINQ stored procedure versus a LINQ query?

View 1 Replies

Linq To Entities. GetPropety(name).GetValue Not Recognised By Linq?

Apr 20, 2011

I have a listbox on my xaml form that I bound to a List(Of MyType) property. I populated this list like so:

Dim fields As List(Of CheckableFields) = New List(Of CheckableFields)
Using context As ITIPEntities = New ITIPEntities()
Try[code]....

Now I'm at the point where the user selects the fields they want included in a report and I need to iterate over the required fields. This is my linq query:

For Each checkedField In _requiredFields
If checkedField.IsChecked Then
If checkedField.FieldData IsNot Nothing AndAlso checkedField.FieldData.Trim IsNot String.Empty Then[code].....

View 1 Replies

How To Get Lamda In LINQ To Actually Filter For Dynamic Linq

Sep 10, 2009

Example-I have a person class

Public Class Person
Private _fname As String
Public Property Fname() As String

[Code]...

View 2 Replies

LINQ Query Using The Dynamic LINQ Library?

Mar 31, 2011

Forgive my ignorance on this.I have this LINQ Query:Dim ngBikersDataContext As New CarBikeWalkDataContext

bikersList = (From c In ngBikersDataContext.Reg_Bikers _
Order By c.L_Name _
Select New Bikers() With { _
.BikerID = c.BikerID, _
.F_Name = c.F_Name, _

[Code]...

with the error "Overload resolution failed because no accesible 'Select' accepts this number of arguments."
Over the "NEW" I get an error " ')'expected."

View 1 Replies

"System.ArgumentException: An Item With The Same Key Has Already Been Added." When Trying To Order An In-memory LINQ Query By A LINQ Association?

Jan 27, 2011

We are doing a query against an in-memory collection of LINQ data objects. The wrinkle is that we are ordering by a column in a related table whose records have not necessarily been loaded yet (deferred loading:)

Dim oPkgProducts = _
From b In oBillPkg.BillProducts _
Where b.Successful.GetValueOrDefault(Common.X_INDETERMINATE) = _

[code]....

View 1 Replies

.net - Linq Expressions With Linq To Entities?

Feb 28, 2012

The pattern I'm trying to avoid is checking if a string (normally a control's text value) is null/empty, and if it is, comparing it using Contains to a field in my data. Obviously the field isn't hard-coded into my extension, neither is the object type.What I've got works perfectly in Linq to Objects, but I get the generic run-time error "LINQ to Entities does not recognize the method 'System.String Invoke(GenericQueryHelper.Customer)' method, and this method cannot be translated into a store expression." when using an entity framework model.

Here's what I have:

<System.Runtime.CompilerServices.Extension()>
Public Function CompareAndFilter(Of T)(source As System.Linq.IQueryable(Of T), expressionField As System.Linq.Expressions.Expression(Of System.Func(Of T, String)), compareTo As String)

[code]....

I want my usage to look something like this:

Dim results = repository.Customers.CompareAndFilter(Function(c) c.FirstName, searchText)

I do need to get this running against a SQL database really, as it is filtering results, so I don't want to be doing that in memory.

View 2 Replies

C# - Convert Code LINQ To SQL In C # LINQ To SQL In .net?

Jun 27, 2012

How can I convert this code LINQ to SQL in C # LINQ to SQL in Vb.net

[Code]...

View 2 Replies

LINQ To SQL - Add In Row_Number To A LINQ To SQL Query?

Aug 31, 2011

How do I add ROW_NUMBER to a LINQ query or Entity? How can I convert this solution to VB.NET?

[Code]...

I'm having trouble porting that last line. I have been unable to locate a VB.NET example. I'm actually not looking for any paging functionality like the example provides, just good old-fashioned Row_Number(Order By X) row index.

View 1 Replies

Convert An Object System.Data.Linq.DataQuery To System.Linq.IQueryable?

Oct 21, 2009

How can I convert an object of type System.Data.Linq.DataQuery to System.Linq.IQueryable?I'm working with Visual Basic/Silverlight, and the source code of my query is as follows:

Public Function Get_Cli_Pag() As IQueryable(Of V_Cliente_Pagare)
Dim Qry = From P In Me.Context.Pagares Join C In Me.Context.Codigos On C.Codigo

[code]....

View 1 Replies

VS 2010 Upgrade From 2008 To 2010 - Now LINQ - IntelliSense Is Not Working For LINQ Stuff

Apr 20, 2010

I just upgraded a project from VB 2008 to VB 2010. Before, the project did not use LINQ. I have started implementing it. So, I have updated the target framework from 2.0 to 3.5, and added a reference to System.Core, and imported the namespace System.LINQ to the entire project and also imported System.Data.LINQ into the form I'm working with (because it was not available in the list for Imported Namespaces in the references tab).

It's not throwing any errors now, but my IntelliSense is not working for LINQ stuff.

For example... I write this:

[CODE]....................

Then, if I type S. on the next line, the IntelliSense doesn't grab what it should for S (Only get Equals, GetHashCode, GetType, ReferenceEquals, and ToString, instead of the options I should get like Count, First, FirstOrDefault, etc...). If I Type S.First. then its the same thing, no IntelliSense that lists the available fields for S, just the standard options (Equals, GetHashCode, GetType, ReferenceEquals, and ToString). I should be seeing my column names in my table when I type S.FirstOrDefault.

So any ideas what is going on? When I type the code, for example, MessageBox.Show(S.FirstOrDefault.FirstName), it works perfectly. But it doesn't change the casing of the text (so it would read s.firstordefault.firstname) and no intellisense while doing it. But no errors. BTW - Everything works perfectly when creating a NEW VS 2010 application, it's just my projects upgraded from Visual Basic 2008 that have this issue.

View 2 Replies

LINQ Query Is Enumerated - Turn On Some Kind Of Flag That Alerts Me Each Time A LINQ Query Is Enumerated?

Sep 22, 2009

I know that LINQ queries are deferred and only executed when the query is enumerated, but I'm having trouble figuring out exactly when that happens.Certainly in a For Each loop, the query would be enumerated.What's the rule of thumb to follow? I don't want to accidentally enumerate over my query twice if it's a huge result.

For example, does System.Linq.Enumerable.First enumerate over the whole query? I ask for performance reasons. I want to pass a LINQ result set to an ASP.NET MVC view, and I also want to pass the First element separately. Enumerating over the results twice would be painful.It would be great to turn on some kind of flag that alerts me each time a LINQ query is enumerated. That way I could catch scenarios when I accidentally enumerate twice.

View 3 Replies

Converting Linq To C# Linq?

Feb 22, 2012

I recently switched from VB to C# and have, for the most part, been able to make the transition without too much trouble. Currently I am working on converting a VB.Net program into C# and am having trouble with a couple of code blocks that include Linq.

This is one of the VB.Net lines of code that I am having trouble with:

I have tried to do the same thing in C# like this:

I am getting a compile error on the dt, which says Could not find an implementation of the query pattern for source type 'System.Data.DataTable'.'GroupBy' not found. VS also has issues with the whole into Emailers = group;

I have tried to get this right using examples from my search but have not been able to get it right.

View 2 Replies

Linq .Where With An OR Instead Of An AND?

Jul 28, 2009

suppose I wanted to make a function that returned a list of people based on 2 criteria ... FirstName = 'Ed' Or LastName = 'Smith'.The key here being the OR. If I do something like the following:

dim qry = From p in db.Person select p.FirstName, p.LastName
qry = qry.Where(Function(p) p.FirstName = 'Ed')
qry = qry.Where(Function(p) p.LastName = 'Smith')

[code].....

View 7 Replies

VB Linq To C# Linq?

Oct 19, 2011

convert it to C# equivalent

Dim dtData As DataTable = Session("Data")
Dim aFilters = From oRow In dtData _
Where oRow(i_oColumn.BaseColumnName) IsNot DBNull.Value _

[Code].....

View 1 Replies

Way To Use Linq

Jul 6, 2011

My friend told me some linq and mysql.

I not know what is LINQ.

is dll?

is addins for visual studio?

where do i download?

View 2 Replies

XML To SQL Using Linq?

Sep 22, 2010

I am having some difficulties with sending XML data to SQL using Linq.I have been following the tutorial link below, however my XML data doesn't contain a root value like <order number> to go through each of the XML data. There is no unique reference as part of the <quote> information.[URL]..

Is there a way I can submit the changes to SQL using the <reference> field as the unique field even though it is not related to <quote>?

[Code]...

View 9 Replies

.net - Converting VB Linq To C#?

Apr 12, 2011

I'm in the process of teaching myself C# by converting an existing project and am stuck converting the following vb linq code:

Dim outStuff = From tt In (From t In Products.SelectMany(Function(p) If(p.tags IsNot Nothing, p.tags, New ObservableCollection(Of TagModel)))
Group By tagName = t.name,
v = (Aggregate p In Products Where If(p.tags IsNot Nothing, p.tags.Contains(t), Nothing) Into Sum(p.views)),
nl = (Aggregate p In Products Where If(p.tags IsNot Nothing, p.tags.Contains(t), Nothing) Into Sum(p.num_likes))

[Code]...

var x = Products.SelectMany(p => (p.tags != null) ? p.tags : new ObservableCollection<TagModel>());
var tags = from t in x group t by t.name into g select new { tagname=g.First().name};

View 2 Replies

.net - Grouping Using LINQ?

Feb 5, 2010

I'm having a heck of a time with transforming a simple SQL Query into a LINQ query(using vb btw)

Here is my SQL:
SELECT USRDEFND5
FROM int_gp_employee
GROUP BY USRDEFND5

[Code]...

I've tried a number of different variations of the LINQ. My current statement is:

From b In xmlFile...<row> Group b...<usrdefnd5> By b...<usrdefnd5> INTO group when I foreach through the resulting collection, EVERY line (17000) shows up.

View 2 Replies

.net - InvalidCastExeption In LINQ To XML?

May 17, 2011

I am using LINQ to XML to take some data from resources , and here I have a function, where I take some values and then I create a new object (Type Translation), so when I call the function I get a Translation object. By now I have this code:

Public Shared Function RetrieveTranslation(ByVal file As String) As List(Of clsTranslation)
Dim valuetrans = From vl In XElement.Load(file).Elements("data") Select (New clsTranslation With {.Filename = file, .Value = vl.Element("value").Value, .TranslationId = vl.Attribute("name").Value})
Return valuetrans
End Function

The problem is that with this code I got this error:

Unable to cast object of type 'WhereSelectEnumerableIterator2[System.Xml.Linq.XElement,clsTranslation]' to type 'System.Collections.Generic.List1[clsTranslation]'.

View 1 Replies







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