exception "Failed to convert parameter value from a String to a DateTime."
-
Saturday, February 16, 2008 7:30 AM
hi frnds ........this is my scenario......please help me in this exception.......
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickDim
fs As New FileStream(path, FileMode.Open, FileAccess.Read) Dim br As New BinaryReader(fs) Dim bytes() As Bytebytes = br.ReadBytes(fs.Length)
cmd.Connection = concon.Open()
cmd.CommandText =
"insert into licence values('" & mcode.Text & "','" & vcode.Text & "','" & ltype.Text & "','" & lno.Text & "','" & pno.Text & "',@procdate,'" & lname.Text & "','" & fname.Text & "','" & address.Text & "','" & varea.Text & "','" & PS.Text & "','" & reqweapon.Text & "','" & w1.Text & "','" & ammone1.Text & "','" & ammyear1.Text & "',@proddate1,'" & w2.Text & "','" & ammone2.Text & "','" & ammyear2.Text & "',@proddate2,'" & w3.Text & "','" & ammone3.Text & "','" & ammyear3.Text & "',@proddate3,@vdate,'" & PURPOSE.Text & "','" & remarks1.Text & "','" & remarks2.Text & "',@photo)" Dim p1, p2, p3, p4, p5, p6p1 = cmd.Parameters.Add(
"@procdate", OleDbType.Date)p2 = cmd.Parameters.Add(
"@proddate1", OleDbType.Date)p3 = cmd.Parameters.Add(
"@proddate2", OleDbType.Date)p4 = cmd.Parameters.Add(
"@proddate3", OleDbType.Date)p5 = cmd.Parameters.Add(
"@vdate", OleDbType.Date)p1.value = procdate.Text
p2.value = proddate1.Text
p3.value = Proddate2.Text
p4.value = Proddate3.Text
p5.value = vdate.Text
p6 = cmd.Parameters.Add(
"@photo", OleDbType.LongVarBinary)p6.Value = bytes
cmd.ExecuteNonQuery()
br.Close()
fs.Close()
con.Close()
End
Subi am getting exception as "Failed to convert parameter value from a String to a DateTime."
thank u
in advance
All Replies
-
Sunday, February 17, 2008 7:27 PM
In the Add command you told the command object that the parameters were DateTime object, but then went and tried to set their values to string objects. You either have to set the parameter type to string or convert procdateX.Text to a DateTime (DateTime.TryParse).
-
Monday, February 18, 2008 9:32 AM
hi....
thank u very much for ur reply.....
but can u please help me.......where should i apply it in my code.......
please reply me soon.......
thank u....
in advance,..........
-
Monday, February 18, 2008 9:30 PMCode Snippet
p1.value = DateTime.Parse(procdate.Text)
p2.value = DateTime.Parse(proddate1.Text)
p3.value = DateTime.Parse(Proddate2.Text)
p4.value = DateTime.Parse(Proddate3.Text)
p5.value = DateTime.Parse(vdate.Text)
-
Tuesday, February 19, 2008 5:12 AM
hi ......thanks for replying me.....
my date format are all maskedtextboxes......with mask-shortdate........
when i enter the date in my maskedtextboxes my code is working.......
but anyone of my maskedtextbox is empty......then i am getting the exception........as that
"Failed to convert parameter value from a String to a DateTime."
please help me in this query.......
thank u
in advance....
-
Tuesday, February 19, 2008 3:49 PM
Well, that would make sense wouldn't it? An empty string is not a date. You need to validate data entered by your users before using that data. If your business logic states that an empty string in a date field is valid, then you need to modify your query accordingly. -
Wednesday, February 20, 2008 5:30 AM
hi........
thank u.......my prob has been solved.......thank u very much for sending replies.......


