|
-
Dec 16th, 2003, 04:43 AM
#1
Thread Starter
Fanatic Member
Erorr With Date Formats
I have a problem
My Sql db is sat on a server which i guess is in U.S.A format cos dates are mm/dd/yyyy however im in england and the application is going to be used in england which is formatted like dd/mm/yyyy so in my code ive got this
VB Code:
Dim dteStartDate As Date = CDate(Format(Me.StartDate.Value, "MM/dd/yyyy"))
Dim Cmd As New SqlCommand("InsCalAppointment", MyConnection)
With Cmd
Try
.CommandType = CommandType.StoredProcedure
.Parameters.Add("@dteStartDate", DbType.Date).Value = dteStartDate
.ExecuteNonQuery()
Catch er As Exception
MsgBox(er.ToString)
End Try
An unhandled exception of type 'System.InvalidCastException' occurred in microsoft.visualbasic.dll
Additional information: Cast from string "12/16/2003" to type 'Date' is not valid.
Can any one help me plleaseeeee
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
Dec 16th, 2003, 05:06 AM
#2
Me.StartDate.Value
^ Is that actually a date variable coming back from that control (ie a date picker control) ? There is no point doing a cdate(format( as it cancels itself out, one formats to a string, the other converts to a date varaible. Try just using:
Dim dteStartDate As Date = Me.StartDate.Value
Because you are using parameters, it wont matter what format you send it, as long as its a datetype (date-types dont actually have formats, just a localized return value).
Heres how I have done mine, and it works fine: (yes its oledb)
Code:
Dim NewItem As New OleDb.OleDbParameter("ParamName", OleDb.OleDbType.Date)
NewItem.Value = ParamObject
dbCommand.Parameters.Add(NewItem)
-
Dec 16th, 2003, 06:25 AM
#3
Thread Starter
Fanatic Member
Sorted its now done thanks
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|