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 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:
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
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 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?
I am getting an unexpected result parsing a string into a date string. Here is the code snippet I'm using to test: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
I'm trying to load a datable into a datagridview, but column1 ("date") should be converted to a datetime, so I can sort it when I click on the datagridview header. I tried this, but it gives me that there is no column 0 or one. I have 2 columns: "ID" and "DateStart"
I've got a datatable with a DateTime field that I want to sort using a DataView. I only need the Time part of the column though, and not the date. I can't get it to show just the time and not the date as long as its a DateTime column. I know I could convert it to a string to get the time, but then it wont sort correctly.
I am having a major issue understanding why this code runs fine once and then when run a second time causes the "String was not recognized as a valid DateTime." exception. This program loops through folders and subdirectorys and retrieves the file dates from the last modified date of the file , Its only when i click New Report to reset all the values in the settings which clears all object lists and resets all the other values that this issue occurs.
This is the value being passed to this function: #6/14/2011 4:46:51 PM# (The file inside the subdirectory,s last modified date.)
The function is Public Sub setFileDate(ByVal fileDate As DateTime) 'Format the datetime from the filedate to a UK culture. Dim myDateTime As DateTime = DateTime.Parse(fileDate, ukCulture.DateTimeFormat) 'Set the current files date. dFileDate = myDateTime.Date [Code] .....
I'm just converting a date to a string but I'm getting this error. It's not listed as one of the normal exceptions to the datetime.tostring method. Googling around, it looks like it's an actual bug where it thinks StartDate is an int--but that's no help to me, as I just need to convert the date.
dim StartDate as nullable(of date) dim Date1 as string if not StartDate is nothing then Date1 = StartDate.tostring("yyyy-mm-dd") end if
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 have a DataTable with two DateTime columns: "start_time" and "end_time".Now, I want to add a third column that calculates the difference between the two DateTimes. But I can't seem to figure out how. I've tried to set the .Expression-value to "start_time - end_time", but it says that "-"-operator is not allowed on DateTime.
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
[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.
I have a Nullable DateTimePicker but it lacks a vital property, that is to be able to change its ForeColor, anyone who has some suggestion on how can this be done? Or perhaps a free nullable DateTimePicker out there that supports changing of backcolor and forecolor?This is C# but it should not be different with .Net, and I prefer posting it here since there is more traffic here over the C# section.
using System; using System.Collections.Generic; using System.ComponentModel;[code].....