when saving the "conversion failed when converting datetime from character string" is displayed. Please help

Private Sub BtnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
Dim cn As New SqlConnection(ConnectionString)
put = "insert into NewAccount(Account_no,Surname,First_Name,sex,Date_Applied,Date_Birth,Contact_no,Contact_Address,Acco unt_type,Branch_ID)values('" & Me.TxtAddress.Text & "','" & Me.txtAccount_No.Text & "','" & Me.txtSurname.Text & "','" & Me.txtContact_Address.Text & "','" & Me.cboAccount_type.Text & "','" & Me.cboBranch_id.Text & "','" & Me.dtDate_Applied.Textmaskformat & "','" & Me.dtdate_birth.Textmaskformat & "','" & Me.txtFirst_Name.Text & "','" & Me.cbosex.Text & "')"
da = New SqlDataAdapter(put, ConnectionString)
da.Fill(ds, "NewAccount")
Catch ex As Exception

End Try
End Sub

In database the datatype is Datetime and ur passing String from Front end so its causing the error. Either make the datatype as varchar in DB or pass the date from front end

in the propertis of textbox mask is date format:-'00/00/0000' When i Changed to dateTimePicker, I had the same error. am uing Maskedtextbox for date field for the front end.
What is the actual cause of the error.
Please advice

try using a string variable and then pass your date and time value to it. then use another date data type variable, give it your string value(date/time). then use your date datatype variable for inserting your data into the database.

it may be ambigous but it worked for me. :)

Dim x As String = "15/Feb/2011"
   x = Convert.ToDateTime(x)

try something like this...

This article has been dead for over six months. Start a new discussion instead.