A problem with dates
A problem with dates
A problem with dates
A problem with dates
A problem with dates
A problem with dates A problem with dates A problem with dates A problem with dates A problem with dates A problem with dates A problem with dates A problem with dates
A problem with dates A problem with dates
A problem with dates
Go Back  Xtreme Visual Basic Talk > > > A problem with dates


Reply
 
Thread Tools Display Modes
  #1  
Old 05-13-2007, 11:48 AM
CaJack CaJack is offline
Newcomer
 
Join Date: Mar 2007
Posts: 23
Default A problem with dates


Hi,
I keep getting an error when I run my code. Here’s the error “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”. It points to this part of my code…
Code:
 cmd.ExecuteNonQuery()
Here’s my code…
Code:
    Private Sub TestDate()
        Dim DateClosedString As String = "Closed"
        Dim cnn As Data.SqlClient.SqlConnection
        Dim cmd As Data.SqlClient.SqlCommand
        Dim TodayTest As Date = Today
        Dim strSQL2 As String

        strSQL2 = "Update TestTBL SET DateStatus = '" & DateClosedString & "' WHERE EndDate >= '" & Today & "'"
        Dim conn As String
        conn = "Data Source=.\SQLEXPRESS;AttachDbFilename=""|DataDirectory|\aspnetdb.mdf"";Integrated Security=True;User Instance=True"
        cnn = New Data.SqlClient.SqlConnection(conn)
        cmd = New Data.SqlClient.SqlCommand(strSQL2, cnn)
        cnn.Open()
        cmd.ExecuteNonQuery()
        cnn.Close()
End Sub
What I want it to do is check my TestTBL and if any EndDates are greater or equal to todays date, write closed to the DateStatus field.
The dates are saved to the database as DateTime. This is copy and passed from an enddate field in my database “22/05/2007 00:00:00”. I’m not really need the time part but I cant find any other way.
Can anyone help? I’ve been pulling my hair out over this one for days.
Reply With Quote
  #2  
Old 05-15-2007, 05:36 AM
Shurik12A problem with dates Shurik12 is offline
Steppe Walker

Retired Moderator
* Expert *
 
Join Date: Jul 2002
Location: Ukraine/Russia/Belgium
Posts: 7,227
Default

Hi,

Isn't it about applying Format(..) function?

Regards,
Shurik.
__________________
"A diaper is not like a computer that makes satisfying burbling noises from time to time, hinting at great inner complexity." Malcolm Gladwell

"I'm sitting here completely surrounded by no beer." Onslow, 'Keeping up appearances'
Reply With Quote
  #3  
Old 05-15-2007, 03:14 PM
CaJack CaJack is offline
Newcomer
 
Join Date: Mar 2007
Posts: 23
Default

Yep, I think your right. Thanks.
Reply With Quote
  #4  
Old 05-16-2007, 07:39 AM
MKoslof's Avatar
MKoslofA problem with dates MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Use a stored procedure and simply pass a valid SQL DataTime Parameter back. Let the procedure do all the formatting for you, just feed it the proper parameter type and value .
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
A problem with dates
A problem with dates
A problem with dates A problem with dates
A problem with dates
A problem with dates
A problem with dates A problem with dates A problem with dates A problem with dates A problem with dates A problem with dates A problem with dates
A problem with dates
A problem with dates
 
A problem with dates
A problem with dates
 
-->