0

I have a asp.net project where i have to get input from the user and insert it into date attribute in my database. but instead I have only 0000/00/00. I can't understand why.

the input comes from 3 text boxes. Than i concatenate them and pass it to the query. But something goes wrong. here is the code:

Bday = Month2.Text & "/" & Dates2.Text & "/" & years.Text
Dim StrQwery As String = "INSERT INTO account VALUES(accoint_id, '" & Bday &"')"
Dim smd As MySqlCommand = New MySqlCommand(stquery, myconn)
smd.ExecuteReader()

The same thing happens when I add time to the same string and want to pass it to the dateTime attribute. Can someone tell me what is wrong?

regTime = Month2.Text & "/" & Dates2.Text & "/" & years.Text & CStr(TimeValue(CStr(Now)))
Dim StrQwery As String = "INSERT INTO account VALUES(accoint_id, '" & regTime &"')"
Dim smd As MySqlCommand = New MySqlCommand(stquery, myconn)
smd.ExecuteReader()
meks
  • 777
  • 3
  • 12
  • 23
  • Try to use the [**prepared statements**](http://dev.mysql.com/doc/refman/5.0/en/connector-net-programming-prepared.html), [Prepared Statements in VB.NET](http://stackoverflow.com/questions/7351135/prepared-statements-in-vb-net) – Mahmoud Gamal Apr 27 '13 at 21:46

1 Answers1

0

MySQL's date-as-string format is yyyy-mm-hh and yyyy-mm-dd hh:mm:ss for datetime. If you insert anything else, like your xxxx/xx/xx, MySQl will not even TRY to guess what format it's in, and simply insert a 0000-00-00 to signal an invalid date.

This is not something you can change. Convert your dates to MySQL's standard format, or deal with the consequences.

Marc B
  • 356,200
  • 43
  • 426
  • 500