C# - DateTime Nullable Exception As A Parameter?
May 8, 2009
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.
On this line -->
dgvSearchResults.DataSource =ConnectBLL.BLL.Person.Search(_firstName,_middleName,_lastName,_sSN, (DateTime)_birthDate,_applicationID,_applicationPersonID,_fuzzy);
[Code]....
View 4 Replies
ADVERTISEMENT
Nov 13, 2011
I tried the following, but i get the error
constant expression is required
Public Sub ExampleSub(ByVal Test as string,
Optional ByVal fromDate As System.Nullable(Of DateTime) = Date.Today)
'A Great sub!
[Code].....
View 3 Replies
Nov 17, 2010
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:
if (origEndDate == origEndDate) { }
and it will come back as true.
View 4 Replies
Jun 3, 2010
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)
[Code]...
View 4 Replies
Nov 15, 2010
I'm having problems with a Nullable DateTime in VB.NET (VS 2010).
Method 1
If String.IsNullOrEmpty(LastCalibrationDateTextBox.Text) Then
gauge.LastCalibrationDate = Nothing
[code].....
View 2 Replies
Nov 17, 2009
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.
View 2 Replies
Apr 7, 2010
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
[code].....
View 4 Replies
Mar 23, 2011
I'm trying to use the type Boolean for some parameter.
<AttributeUsage(AttributeTargets.Method, Inherited:=True, AllowMultiple:=False)>
Public Class MyAttribute
Inherits Attribute
[code].....
View 14 Replies
Mar 3, 2011
I have the following VB.NET function, for example:
Public Function MyFunction (Of TData) (ByVal InParam As Integer) As TData
End Sub
How do I, in a function, determine if TData is a NULLable Type?
View 3 Replies
Jan 18, 2010
how to implement Nullable Parameter of type string in vb.net
Function:
sub savedetail(byval name as string, byval age as integer)
if name isnot nothing then
some work
end if
[code]....
View 1 Replies
Jan 18, 2010
How can I create a nullable numeric optional parameter in VB.NET?
View 3 Replies
Oct 2, 2009
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.
View 1 Replies
Sep 28, 2010
My question is with regards to SqlCommand parameters in VB.NET. I have a database table which contains a datetime column, and I am trying to return all records between a daterange / time. I am using the syntax 'WHERE recordDate BETWEEN @StartDate AND @EndDate', and specifying the parameters using sqlComm.parameters.addwithvalue("EndDate", datetimeVar), etc.
My issue here is that when my datetimeVar contains '8/31/2010 11:59:59 PM', it ends up getting rounded to '9/1/2010'. I can only tell this by the results I am getting back, which include the records from '9/1/2010 12:00:00 AM'.
Am I missing something here or is this a bug? The parameter is of type DateTime, and the value is correct at runtime. In the meantime I have no issues if I write the datetime into the sql string itself ('WHERE recordDate BETWEEN '" & datetimeVar
& "' AND ...), but obviously I would prefer to use parameters for this.
View 3 Replies
Oct 22, 2011
I am trying to store a time from my textbox field value but I got this exception error,Failed to convert parameter value from a TimeSpan to a DateTime.[code]
View 1 Replies
Apr 27, 2011
i'm trying to execute a SQL stored procedure with a parameter that needs the SQL datetime format as:
Dim str_runproc As String
str_runproc = "exec UP_stopactivity @Activity='" & DGV_currentactivities.CurrentRow.Cells(0).Value & "' ,@Client='" & DGV_currentactivities.CurrentRow.Cells(2).Value & "',@starttime='" &
DGV_currentactivities.CurrentRow.Cells(3).Value & "'"
the DGV_currentactivities.CurrentRow.Cells(3).value is a datetime value that is put into a Datagridview via another stored procedure. When I run it in sql, it lists as a correct SQL datetime: 2011-04-27 05:54:51.003, in the datagridview it lists as: 27/04/2011 5:54:51
View 2 Replies
Nov 25, 2011
I am inserting data from vb.net to oracle but I am unable to insert datetime except date into oracle. I want to insert date and also time of entry into database:
cmd.Parameters.Add(":STARTING_DATE", (OleDb.OleDbType.[Date].))
cmd.Parameters(":STARTING_DATE").Value = DateTime.Now()
cmd.Parameters(":STARTING_DATE").Value = txtStartDate.Text
View 1 Replies
Jun 13, 2011
I am having trouble with a mySQL query with the .NET connector. When I create the query, it automatically creates my parameters as objects. I usually change the type to the correct type, which in this case is Date, but I get different results passing in the parameter as a date.When I do "Preview Query" as an object, I get the correct results, but bad results as a Date. I would just leave them as objects, but it errors out when I try to pass a date in.Here's the part of my query that I'm having trouble with:
(Tickets.Resolved >= str_to_date(@startDate, '%m/%d/%Y')) AND (Tickets.Resolved <= str_to_date(@endDate, '%m/%d/%Y')) AND
(Tickets.Status = 'resolved' OR
Tickets.Status = 'rejected')
View 2 Replies
Mar 3, 2011
I have a stored procedure which updates a database using the parameters I supply but I'm having trouble passing a NULL to the stored procedure
The field I need to make NULL is a DateTime field
DB.Parameters.AddWithValue("@date", NULL)
This gives me the error 'NULL' is not declared. 'Null' constant is no longer supported; use 'System.DBNull' instead
[Code]...
View 3 Replies
Nov 21, 2011
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
View 11 Replies
Mar 27, 2009
I get this error from my application, but not in the development environment (VS 2008). I created an installer package and have installed it on two different XP machines with no problem. However, on a Vista system when the application runs code to generate an image I get a "Parameter is not valid" exception. I have no clue what could be causing this given the circumstances. To generate the image I am creating a bitmap with a valid size and simply creating the graphic. Since I can't repoduce the error in VS I don't have a way to troubleshoot this.
View 7 Replies
Nov 23, 2009
I am using VB.Net code to print barcode label in Zebra TLP 2844 printer. And the printer is connected to system by USB port. When i execute the code i get an error "Invalid Parameter : Name handle" in the line outFile = New FileStream(_SafeFileHandle, FileAccess.Write) . As this is a USB port So i shared the printer and used the UNC path. But still i get the error. Below is the complete code
[Code]....
View 3 Replies
Dec 10, 2009
I am running the same program on two workstations. One reveals no errors while the other shows a "COM exception error: invalid parameter." The offending line of code is shown below.Is there an explanation for the inconsistency?
.SeriesCollection(iRet).Name = "=""Q" & Str(iRet) & """"
View 1 Replies
Mar 15, 2010
I have a text string like this which I will need to parse: FriMar1200:00:00EST2010 And I used the following Date.ParseExact("FriMar1200:00:00EST2010", "dddMMMddHH:mm:sszzzyyyy", Nothing) And it is giving me a A first chance exception of type 'System.FormatException' occurred in mscorlib.dll error.
View 2 Replies
May 2, 2012
If the parameter variable is not passed then this code throws an exception of "Conversion from string "" to type 'Date' is not valid."
This is my code.
Public Shared ReadOnly Property Request_projectStartDate() As Date
Get
Dim _value As String = Nothing
[Code] .....
View 2 Replies
Feb 17, 2011
am getting the above exception while swaping Items in the list(lstRoutePriority).PFB my code
if (lstRoutePriority.SelectedIndex > 0)
{
//Swap the two items
[Code].....
View 2 Replies
Jun 22, 2011
've got a function that takes two parameters (a delegate and an integer) and then creates a LINQ MethodCallExpression, which it uses to gets the results:
Public Delegate Function CompareTwoIntegerFunction(ByVal i1 As Integer, ByVal i2 As Integer) As Boolean
Public Function Test(ByVal pFunc As CompareTwoIntegerFunction, ByVal i1 As Integer, ByVal
[code].....
View 1 Replies
May 8, 2009
It is possible to catch an exception and throw a new exception which wraps the first exception as an inner exception: [URL] Also, if I call a function and it throws a certain error, but I catch it, will the calling code's catch handler execute? If so, and it is of a higher exception type, is this not wrapping the exception? eg I can throw exception ex of type IndexOutOfRange, log it but rethrow, catch a higher up exception and do something, or I can throw a new exception and wrap an inner exception like:
View 1 Replies
Mar 23, 2011
how to convert string to datetime and calculate date
View 3 Replies
May 7, 2010
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.
View 1 Replies
May 1, 2010
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.
View 1 Replies