I am a c#/asp.net developer and I am having to work on a VB/asp.net. I have two variables
Dim originalDate as DateTime?
Dim newDate as DateTime?
Both nullable datetimes, originalDate is a nullable date I am getting from the database and newDate time is set in code, I need to compare them, they can either both have dates, neither have dates or one have and one not.
I have a bit of code as follows:
if origEndDate = origEndDate then
When both origEndDate and origEndDate are "nothing" this statement is false (well when I run it in the watch window it comes back as nothing)!I don't understand why this is the case because I was under the impression doing an "=" compares the two values and as they are the same surely it should be true? What syntax should I be using as in C# I can do the above as so:
For a project I need to convert a date field in my SQL Server 2008 Database into a VB.net ListOf. Most of the records in StartDate field are NULL. VB.net doesn't recognize null values for DateTime.I need the NULL values to be dismissed, as they will be returned in a ListOf for a web service that I'm creating.
Here is my syntax and a sample of the current returned values in the XML message of the ListOf:
Class Property StartDate() As System.Nullable(Of DateTime) = Nothing asmx.vb myUserRoleAppInfo.StartDate = myPermissionUser.StartDate XML Message (Listof)
I have a Search Form that can search by a few different fields. The problem field is birthDate. On the form it is a string. In the SQL 2005 db it is a DateTime that can be null.
The code below is sequential as far as declaring the variable on the form and then setting it. Then the call to the BLL and then the call to the DAL.
I am struggling with a nullable datetime column [DateInsp] in an ASP.NET app which uses SubSonic3, Linq, MS SQL Server 2005.I had this all working when the datetime column [DateInsp] did not allow nulls. A new requirement forced me to set the [DateInsp] column to allow nulls and now I am struggling getting this piece of functionality to work properly again.
Problem 1:I need to first render a dropdown list of the 7 most recent inspection dates for a given inspector (this is a grouped list of the 7 most recent dates for the inspector). Here is the TSQL that I need to convert to Linq syntax:
declare @InspectorID varchar(5) set @InspectorID = 'GPA' select top 7 convert(nvarchar(30), [DateInsp], 101) InspectedDate
[code]....
If I can't get this work properly using Linq, BUT I can/could build a stored proc to return the list of dates and throw that into a dropdown. Fair enough. I've been fighting with the Linq syntax?
Problem 2: I need to use the selected date in the dropdown mentioned above to pull the correct records for this inspector and the correct date. Again, this is a nullable datetime field and this is real sticking point for me.
Here was the original Linq syntax that accomplished the requirement before I had to change the datetime field to allow Nulls:
Dim query = (From i In db.IncomingInspections _ Where i.InspectorID = User.Identity.Name _ Group By Key = New With {i.DateInsp} Into Group _
[code]....
For some reason I can't use the .Value property; I get: The member 'Value' is not supported I get: "Incorrect syntax near '<'." if I try to add the date comparison to the where clause too.
constant expression is required Public Sub ExampleSub(ByVal Test as string, Optional ByVal fromDate As System.Nullable(Of DateTime) = Date.Today) 'A Great sub!
I have a date time picker bould to a Nullable Datetime field in a sql server datatable. The ShowCheckBox option is set to true. If the user unchecks the checkbox on the datetimepicker I would like to the field to be set back to null in the DataTable. The default behaveour does not seem to do this and there is no specific event for the uncheck.
Private Sub dtpCertDate_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtpCertDate.ValueChanged If dtpCertDate.Focused Then
I am fetching DataTime value of a SQL Database, LockDate. Dim diffDate As TimeSpan diffDate = DateTime.Now - LockDate minutes = Convert.ToInt32(diffDate.Minutes) hours = Convert.ToInt32(diffDate.Hours) Minutes value is showing incorrect values.
I'm tried creating an analog clock and I realized I was terrible at trig and gave up. So instead I'm just creating a digital clock. I'm having problems getting the alarm to go off. Lemme explain my layout, I have 3 comboboxes. 1 is for the hour, 1 is for the minute and 1 is for am/pm.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 'The commented out variables are global
I'm working on a automated content updating script. When a new update is entered I insert into a database table, and cache, the time of the update. Dim setT As DateTime = DateTime.Now modCommand2.Parameters.Add("?brmt", setT) modCommand2.Parameters.Add("?lup", setT) 'databse code here Dim myData As String = CType(Cache("ltu"), String) ' if it's not there, add it If myData Is Nothing Then Cache("ltu") = setT Else Cache.Remove("ltu") Cache("ltu") = setT End If
Actually I have datetime value stored in the database. What I am taking from the textbox is a time value. I want to extract those results from the database which are between the given time value....To be more concise, my application is a booking system for a sports club and provides an option to view alreaady made bookings.. Here i offer two options either to view all bookings for a specific game or to filter bookings. In filter bookings one option is to filter through date and time...Date option is running okay but problem lies in time part...I provide two times but unable to view bookings between them...
My code is:
Dim prmtimefrom As New SqlParameter("@booking_time", SqlDbType.DateTime) prmtimefrom.Value = TextBox3.Text Dim prmtimeto As New SqlParameter("@booking_tim", SqlDbType.DateTime)
I am looping through a list of DateTime variables and have got the .ToUniversalTime variable. I want to find out from the list which is the closest one approaching Now.ToUniversalTime but am having difficulty trying to work it out I had it looping through like this but this isn't much good as I only want to return the one that is the closest approaching to the system time. If TodaysCard(i).eventDate.ToUniversalTime < Now.ToUniversalTime
I have a web app that sets a var setT to DateTime.Now. This var is used to set a "lastUpdate" field in a database and Cache("ltu"). This value is also added to a cookie. the problem I'm having is that comparing the cookie value and the cahed value show that the cookie value is earlier than the cached value, eventhough it is the same value that cam from the setT var.I'm assuming that the fractional seconds are being set to 0000's in the cookie by some means which is the only explaination I can come up with.Now, Is there some way I can set the origianal setT DateTime.now value to not have fractional seconds, or zero fractional seconds?Do you think I'm going about this correctly?
Im working on my first n-tier application. I am trying to serialize a structure and Im getting an error"Soap Serializer does not support serializing Generic Types : System.Nullable`1[System.DateTime]."Here is the structure that is being serialized Namespace Structures
<Serializable()> _ Public Structure structAllergy Public AllergyID As String Public ProfileID As String
[code]....
The bold line is the line that is throwing the error.
I'm trying to match a certain DateTime value with the current system DateTime. I have a timer and a label on a form. Timer interval is set to 1000. When the form loads, the timer starts ticking. As soon as the current DateTime matches the value of the variable, it shows a message in the label. When I'm writing the following code, the values don't match even if the current system DateTime is equal to the variable. Label1 isn't showing 'Times Matched':[code]The default format of 'Now' is the same as I have stored in dtmVar variable. So there's no question of format mismatch. Does that mean 'Now' is not actually a DateTime property? Provided, my O.S. is Windows Vista Ultimate and all date/time settings are set to default.
I'm trying to match a certain DateTime value with the current system DateTime. I have a timer and a label on a form. Timer interval is set to 1000. When the form loads, the timer starts ticking. As soon as the current DateTime matches the value of the variable, it shows a message in the label.
When I'm writing the following code, the values don't match even if the current system DateTime is equal to the variable. Label1 isn't showing 'Times Matched':
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim dtmNow As DateTime
[Code]....
Why is it so? The default format of 'Now' is the same as I have stored in dtmVar variable. So there's no question of format mismatch. Does that mean 'Now' is not actually a DateTime property? Provided, my O.S. is Windows Vista Ultimate and all date/time settings are set to default.
datetime1 and datetime2now two fields are have data ( date )in table recordi want to update only datetime2 is an emptyi am using visual basic 2010 ( visual studio 2010
I accidently wrote some code today that was like this[code]...
I immediately noticed the issue, but I had already hit the run button. It compiled successfully, I ran it through to the section and it threw an exception.
You can't do this in C#, it gives a compile error "cannot convert from 'int?' to 'int'".
Is there an 'Option Explicit' type switch that I can turn on to ensure that this sort of error does not occur again?
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?
Assume the following program is started at 1:59:01 AM on 3/13/2011 in the United States. The first time Timer1 ticks what will be the value of the TimeSpan (ts)?
Public Class Form1 Private Sub Timer1_Tick(sender As System.Object, _ e As System.EventArgs) Handles Timer1.Tick
I'm trying to add the date and time of Today into a Sql-database-field that has the datetype datetime.
[Code]...
the msgbox gives me the following result: 29/01/2011 18:49:21 my sqlException gives me the following error: 102 - Incorrect syntax near '18'. Is it better that i set the datatype to char in my sql database? It's maybe a bit easier? When I do that, can I calculate with these date?
[code] "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.The statement has been terminated." [code]
I have: Dim nVar1 As Long?Dim nVar2 As Long?Dim nVarSum As Long?nVar1 = Nothing nVar2 = 5 nVarSum = nVar1 + nVar2 I would prefer the result to end with nVarSum being 5, instead of Nothing. I understand if you add something to an unknown value, you will end up with "somthing + unknown" or x+5 will always equal "x+5" not "5" because you are still carrying around that unknown "x". However, how can I effectively treat an unknown or Nothing as a zero for the purposes of addition in this case?(What is basically happening is that the end user is sending us a data file, this code parses that file and then sums together about 15 fields. If the user leaves those fields blank instead of assigning a zero to them, I need to treat it as if it was a zero for this one addition operation, but all the rest of the code needs to continue seeing it as a Nothing value since the user did not ACTUALLY submit zero... they submitted blank or nothing)
I'm converting an Access VBA app to VB.NET. It has dates defined as variants or objects to handle null values. I thought this would be a great chance to use the Nullable type. But I can't get it to work. Either it is inappropriate for what I am trying to use it for, or I am doing it wrong. Anyone know how to use it? Reader is a SqlDataReader.
[Code]...
I was hoping I didn't have to put a lot of If .. Null statements throughtout the code, but that is my only option unless someone has any other idea.