C# - When Are Two Datetime Variables Equal
Dec 27, 2010
I try to compare Datetime.Now with a Datetime variable I set, using the Datetime.CompareTo() method. I use a timer to compare these every second and display the result, but as the current time approaches the time I set, the result changes from 1 to -1, but never 0, which means these two are never equal. I'm suspecting the Datetime structure contains milliseconds?
View 7 Replies
Similar Messages:
Apr 10, 2010
I want to retrieve all the records where the datetime is greater than or equal to 30 days ago. What is the correct formatting for this line: WHERE Property.dateadded >= NOW -30 days .. Dateadded field is in datetime format.
SELECT TOP (1) Property.Name, Property.Price, Department.DepartmentTitle, Images.ImageId, Property.DateAdded
FROM Property LEFT OUTER JOIN
Department ON Property.DepartmentId = Department.DepartmentId LEFT OUTER JOIN
Images ON Property.PropertyId = Images.PropertyId
WHERE Property.dateadded >= NOW -30 days
View 6 Replies
Jun 29, 2010
I'm trying to combine a date and time from separate variables in my asp.net insert sql. pointers? I'm getting the following error
Conversion failed when converting date and/or time from character string.
[Code]....
View 2 Replies
Aug 8, 2010
i am trying to collect 2 variables from one hyperlink, and use those variables in the page_load to set as session. but i don't know how to collect those 2 variables
such :
<a href="javascript:;" onclick="wsChangeColor('mainData', '#FF0000','#FFE4E1');return false;" title="Change color" id="red">1</a>
i would like to collect '#FF0000','#FFE4E1' or direct set '#FF0000','#FFE4E1' to string then send to pageload, how can i do this by only clicking on it ?
View 1 Replies
Jan 2, 2010
I have this code in javascript: var x = e.mapX; It gets the X-coordinate of a map. What I want to do is that I want to store this into a c# variable. I have a class named Test with an integer property X. I want to store var x into X. In the codebehind, I have this on the Page_Load: Test test = new Test(); Then I am trying this on the javascript code: var x = e.mapX;
View 16 Replies
Jan 21, 2010
I created a UserControl and added a public DateTime property. I want to set this property in Markup (ie. <cc1:MyControl runat="server" id="MyControl1" DateTimeProp="1/1/2010" /> ) however I live in a place with a dd/mm/yyyy date format so it complains if I set something like "20/1/2010". Is there a way to set markup in my local datetime format or do I have to conform to "mm/dd/yyyy"?
View 2 Replies
Apr 1, 2011
I have a problem:
I've created usual Controller and View(Edit view) for editing my Entity (EntityFramework)
Here is view example:
<div class="editor-field">
@Html.EditorFor(model => model.BirthDate)
@Html.ValidationMessageFor(model => model.BirthDate)
</div>
BirthDate is Nullable<DateTime>
but during loading my View I get this exception
The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.
That's because of BirthDate is null in database but it is nullable and I expect that it just leaves the filed empty.
And I have Shared EditorTemplate:
@model System.Nullable<System.DateTime>
@if (Model.HasValue)
View 2 Replies
Feb 9, 2010
I have an XML string which contains Dates formatted "dd/MM/yyyy hh:mm:ss".
I'm loading this XML into a dataset using DataSet.ReadXml().
How can I ensure that this Date is stored in the DataSet as a typed DateTime so that I can Sort, Format and RowFilter on it accordingly.
My test harness is as below:
ASPX Page:
[code]....
View 1 Replies
Jun 1, 2012
obj.From = DateTime.Parse(txtFrom.Text, ci);
And it will give error String was not recognized as a valid DateTime. How it can be solved..
View 1 Replies
Jun 2, 2010
How show local time in datagridview collumn DateTime from database with universal datetime
View 2 Replies
Sep 30, 2010
I am trying to store a SQL Server datetime into MySQL datetime field, but MySQL stores the date value as all zeros. I use this function to trim the fractional part from the SQL Server datetime, but get the same result when trying to store it in MySQL.
[Code]....
View 1 Replies
Nov 15, 2010
I am trying to get data from mysql database and store in sqlserver database. i am getting the following error
The given value of type MySqlDateTime from the data source cannot be converted to type datetime of the specified target column.
View 5 Replies
Sep 13, 2010
I am looking for help on how get a response if xxx does not equal xxx in VB.Net 2008.Here is my original code:
[code]...
View 7 Replies
Jun 23, 2010
I have a simple method which takes an Object and return string "No" or "Yes". Basically I want to display "Yes" or "No" when a bool value of 0 or 1 is there
<asp:TextBox ID="TextBox3" runat="server" MaxLength="50" Width="150px" Text='<%# Checkvalue(Eval("AustResident")) %>' />
But everytime there is a 1 passed to the CheckValue which in the debug shows as true, It never evaluates being equal to "true" what am I doing wrong? My Checkvalue is always returning "No" no matter what I pass.
protected string Checkvalue(object obj)
{
if (obj != null)
{
if (obj.Equals("true"))
{
return "Yes";
}
else
{
return "No";
}
}
else
{
return "No";
}
}
View 3 Replies
Oct 21, 2010
we are using the PeterBlum SelectedIndexCondition to control whether or not some controls are displayed using the following snippet:
PeterBlum.DES.MultiFieldStateController fsc = new PeterBlum.DES.MultiFieldStateController();
PeterBlum.DES.SelectedIndexCondition cnd2 = new PeterBlum.DES.SelectedIndexCondition();
cnd2.Index = desiredIndex
cnd2.ControlToEvaluate = ControlToEvaluate//ListBox, dropdown, etc
fsc.Condition = cnd2;
I'd like to be able to achieve this same functionality except to fire when the desired index IS NOT set. I cannot simply create a bunch of Conditions for each index other than the one I specify due to the way this is dynamically being done in my application.
View 1 Replies
Oct 8, 2010
I am trying to split a collection into multiple collections while maintaining a sort I have on the collection. I have tried using the following extension method, but it breaks them incorrectly. Basically, if I was to look at the items in the collection, the order should be the same when compared to the broken up collections joined. Here is the code I am using that doesn't work:
public static IEnumerable<IEnumerable<T>> Split<T>(this IEnumerable<T> list, int parts)
{
int i = 0;
var splits = from name in list
group name by i++ % parts into part
select part.AsEnumerable();
return splits;
}
int parts = number of sub enumerables
View 5 Replies
Mar 15, 2011
I keep getting an error:Index (zero based) must be greater than or equal to zero and less than the size of the argument list.y code:
OdbcCommand cmd = new OdbcCommand("SELECT FirstName, SecondName, Aboutme FROM User WHERE UserID=1", cn);
OdbcDataReader reader = cmd.ExecuteReader();
while (reader.Read())
[code]...
View 3 Replies
Sep 10, 2010
I'm facing a problem that Google couldn't solve yet!I'm trying to store URLs in an XML file. Problem is that these URLs contain Equal Signs (=) in them. And that generates an error.Here is my code: (**token is a variable that contains the URL)
Dim child As String = vbCrLf & "<Link URL='" & token & "'></Link>"
Dim fragment As XmlDocumentFragment = doc.CreateDocumentFragment
fragment.InnerXml = child
The error message: (Error line and position are meaningless here) '=' is an unexpected token. The expected token is ';'. Line 2, position 133.I've replaced all '&' symbols with '&' in case they were the ones causing the error, but no luck so far.
View 3 Replies
Mar 5, 2011
whats the exact use of static variables in overall programming in .net and for asp.net...
Recently i went for the interview where interviewer asked me 2 question which i was not sure for the same..
whats the use of session object, i said sessions are the server side object, they are used when you want to store user specific data at server side, then he asked what if i want to use static variables for the same, i was mum, can anyone tell me how asp.net will behave if i store the user specific information in static variables.If i use cookies which are the best option to store the data at client side (not sensitive one), but what if user has disabled cookies on his machine, will my application would crash.
View 3 Replies
Feb 18, 2011
I have a basic web form with about 5 textboxes. One Textbox is "Date1" and the other is "Date2." Is there a way to set the value of Date1 = Date2 after the user enters a value into the Date1 textbox? I'm using Visual Studion and C#. I'm not much of a programmer, so the less technical the better.
View 11 Replies
Feb 7, 2011
I'm trying to pass post data from one page to the next but PreviousPage always equals null.This is what I have in the original page (inside an updatepanel
<asp:Button ID="mmGo" runat="server" Text="Merge" PostBackUrl="~/Default2.aspx?action=merge"/>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
[code]...
View 1 Replies
Jun 4, 2010
Im creating a Report to see all I have sold to a Client, my SQL query looks like this
[Code]....
What I dont want is to get a list of repeted items, I want to sum all items that are equal. for exemple:
Current Situation:
[Code]....
What I want to acomplish
[Code]....
View 3 Replies
Aug 30, 2010
I have ASP .NET page, and VB module. I have DropDownlist in the ASP page that retrieve information from SQL database. I am trying to make a string varaible equal the value of the dropdownlist selected.
View 3 Replies
Mar 29, 2010
If I want to validate that a text box contains an integer greater than or equal to zero. Do I need to use TWO asp:CompareValidator controls: one with a DataTypeCheck operator and one with a GreaterThanEqual operator?
Or is the datatype operator redundant? Can I just use a single validator with the GreaterThanEqual operator (and the type set to Integer)?
View 1 Replies
Dec 4, 2010
Here is the code:
Code:
Dim intusercount As Integer = 0
Using connection As New SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True")
Using command As New SqlCommand("SELECT [ID] FROM [Members] WHERE [Username]=@Username AND [Password]=@Password", connection)
command.Parameters.Add("@Username", Data.SqlDbType.VarChar).Value = TextBox1.Text
command.Parameters.Add("@Password", Data.SqlDbType.VarChar).Value = TextBox2.Text
connection.Open()
intusercount = command.ExecuteScalar
connection.Close()
If intusercount > 0 Then
MsgBox("Good")
Else
MsgBox("Bad")
End If
End Using
End Using
Error:
The data types text and varchar are incompatible in the equal to operator.
Source Error:
Quote:
Line 11: command.Parameters.Add("@Password", Data.SqlDbType.VarChar).Value = TextBox2.Text
Line 12: connection.Open()
Line 13: intusercount = command.ExecuteScalar
Line 14: connection.Close()
Line 15: If intusercount > 0 Then
Stack:
Code:
[SqlException (0x80131904): The data types text and varchar are incompatible in the equal to operator.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +2030802
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5009584
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +234
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2275
System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
System.Data.SqlClient.SqlDataReader.get_MetaData() +86
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +311
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +987
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
System.Data.SqlClient.SqlCommand.ExecuteScalar() +139
_Default.Button1_Click(Object sender, EventArgs e) in C:UsersUserDocumentsVisual Studio 2010WebSitesWebSite13Default.aspx.vb:13
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Database:
View 2 Replies