This should be an easy one but I am missing something and have been working on this for two days now.
I am trying to insert a date/time in a short date format (date/time mm/dd/yyyy) into an access database and I get the "Data type mismatch in criteria expression" every time. If I comment out the "startday" I get the "No value Given" which is what I would expect.
Any help here would be greatly appreciated.
Thanks in advance
I am using a master page here if it makes any difference in this instance. :-O :-O
Here is the complete code except the connection string which I have changed:
Sub CrossPage_FirstPage()
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MyConnectionString"
Dim MyCon As New OleDbConnection(strConn)
Dim MySqlDelete As String = "delete from problemdefinition"
Dim MySqlInsert As String = "INSERT INTO problemdefinition (memberage, sex, spouseage, numberchildren, countyid, zipcoderange, startday, dayscov) VALUES (@memberage, @sex, @spouseage, @numberchildren, @countyid, @zipcoderange, @startday, @DaysCov)"
Dim textboxName As TextBox = Me.PreviousPage.Master.FindControl("menu2").FindControl("txtName")
Dim MyDate As String = DirectCast(Me.PreviousPage.Master.FindControl("menu2").FindControl("txtCalendar1"), TextBox).Text
Dim cmd As New OleDbCommand(MySqlDelete, MyCon)
With cmd.Parameters
.Add(New OleDbParameter("@memberage", DirectCast(Me.PreviousPage.Master.FindControl("menu2").FindControl("txtAge"), TextBox).Text))
.Add(New OleDbParameter("@sex", DirectCast(Me.PreviousPage.Master.FindControl("menu2").FindControl("rbgGender1"), RadioButtonList).Text))
.Add(New OleDbParameter("@spouseage", DirectCast(Me.PreviousPage.Master.FindControl("menu2").FindControl("txtSpouseAge"), TextBox).Text))
.Add(New OleDbParameter("@numberchildren", DirectCast(Me.PreviousPage.Master.FindControl("menu2").FindControl("txtNumberChildren"), TextBox).Text))
.Add(New OleDbParameter("@countyid", DirectCast(Me.PreviousPage.Master.FindControl("menu2").FindControl("lblhidden1"), Label).Text))
.Add(New OleDbParameter("@zipcoderange", DirectCast(Me.PreviousPage.Master.FindControl("menu2").FindControl("drpZip1"), TextBox).Text))
.Add(New OleDbParameter("@DaysCov", DirectCast(Me.PreviousPage.Master.FindControl("menu2").FindControl("txtNumDays1"), TextBox).Text))
.Add(New OleDbParameter("@startday", "CDate('" + MyDate + "')"))
End With
Dim result As Integer = -1
If MyCon.State = ConnectionState.Closed Then
MyCon.Open()
cmd.CommandText = MySqlDelete
result = cmd.ExecuteNonQuery()
MyCon.Close()
End If
If MyCon.State = ConnectionState.Closed Then
MyCon.Open()
cmd.CommandText = MySqlInsert
cmd.ExecuteNonQuery()
MyCon.Close()
End If
Dim StartCov As String = DirectCast(Me.PreviousPage.Master.FindControl("menu2").FindControl("txtCalendar1"), TextBox).Text
End Sub