For those new to message boards please try to follow a few simple rules when posting your question.
Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
Keep the subject line brief, but descriptive. eg "File Serialization problem"
Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
No advertising or soliciting.
We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
Below is the piece of code where I am facing a problem,
I basically need a way to return the expected event rows in a datagrid in a WPF application using LINQ. The problem that I am facing here is when I am comparing the column Time which is a datetime type of field with the datetime object dtRunDate, it is not returning any data even the data is present in the table for given condition.
What I have figured so far is that the problem is due to the datetime object dtRunDate doesn't match the format in which the date d.Time is being considered (although can't figure out why the different format is considered as a conversion would have been happening at the data context level).
DateTime dtRunDate = new DateTime();
EventLogDataContext EventLog = new EventLogDataContext();
dtRunDate = Convert.ToDateTime("15/12/2013 18:00:00.000");
var query = from d in EventLog.eventlog_table
where d.Time > Convert.ToDateTime(dtRunDate.ToString("yyyy-MM-dd HH:mm:ss"))
Why are you double-converting dtRunDate in the query? Surely that should just be
from d in EventLog.eventlog_table
where d.Time > dtRunDate
Stick a stop point in there and see what d.Time actually has in it for a few rows, maybe something's wrong with your database or the conversion from database to entity values. As you say the conversion should happen automatically.
In the where clause checking to make sure that the question had not expired. But this is not a required field and sometimes left blank. How to handle to blank condition? I should still show the question, since it never expires. Can I add 10 years on the fly to this blank condition in LINQ? Much appreciated! thanks.
var x = (from dq in db.Questions
where dq.Enabled.Equals(true) &&
(dq.ExpirationDate == null) ? DateTime.Now.AddYears(10) : dq.ExpirationDate >= DateTime.Now
var x = (from dq in db.Questions
where dq.Enabled &&
(dq.ExpirationData ?? DateTime.Now.AddYears(10)) >= DateTime.Now)
If your actions inspire others to dream more, learn more, do more and become more, you are a leader.-John Q. Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering.-Wernher von Braun Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.-Albert Einstein
I´m trying to do a kind of Dynamic lamda expression.
querynew = From res In d Where (res.GetType().GetProperty("Valor").GetValue(res, Nothing)) > q(2)
querynew = From res In d Where res.Valor < q(2)
querynew = From res In d OrderBy res.Valor
I would like to choose the property if I change "Valor" string but when the program run, i have the next error in querynew:
"Conversion from string".valor > 10" to type 'Double' is not valid."
However this works fine:
If d.Item(0).GetType().GetProperty("Valor").GetValue(d.Item(0), Nothing) < 1Then
Anyone know what happend? Is It possible to do this?
d is a list(of datos)
Public Class Datos
Private _Fecha As Date
Private _cMaq As Byte
Private _cSig As Byte
Private _valor As Single
Public Property Fecha As Date
Set(ByVal value As Date)
_Fecha = value
Public Property CodigoMaquina As Byte
Set(ByVal value As Byte)
_cMaq = value
Public Property CodigoSignal As Byte
Set(ByVal value As Byte)
_cSig = value
Public Property Valor As Single
Set(ByVal value As Single)
_valor = value
Public Sub New(ByVal Fecha As Date, ByVal CodigoMaquina As Byte, ByVal CodigoSignal As Byte, ByVal Valor As Single)
_Fecha = Fecha
_cMaq = CodigoMaquina
_cSig = CodigoSignal
_valor = Valor
SELECT SUM(Grades.Grade * Lessons.LesTotalUnit) / SUM(Lessons.LesTotalUnit) AS avg FROM Grades INNERJOIN Lessons ON Grades.LesCode = Lessons.LesCode WHERE (Grades.StNo = @stno) AND (Grades.EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_1 WHERE (StNo = @stno))) AND (Grades.Semester IN (SELECT MAX(Semester) AS Expr1 FROM Grades AS Grades_2 WHERE (StNo = @stno) AND (EduYear IN (SELECT MAX(EduYear) AS Expr1 FROM Grades AS Grades_3 WHERE (StNo = @stno)))))
Last Visit: 31-Dec-99 18:00 Last Update: 20-Dec-13 19:01