DataType Mismatch Errorror
I am working on an application with 28 fields in the datebase and following the examples from "Beginning Visual Basic 2005 Databases".
After spending several days i finally tracked down the fields that are giving me a problem, they are the DateTime datatype.
The query I am using contains this SQL statement.
[u]usp_InsertEmployee</u>
INSERT INTO tStaff (StartDate, BirthDate, Statusdate )
VALUES (@StartDate, @BirthDate, @Statusdate);
The dates are entered into DateTime Picker controls and then converted to date data types with the following code:
'Convert date text boxes to DateTime variables...
dtBirthDate = Convert.ToDateTime(dtpBirthDate.Value)
dtStartDate = Convert.ToDateTime(dtpStartDate.Value)
dtStatusDate = Convert.ToDateTime(dtpStatusDate.Value)
I then set the parameter values with this code:
Using objdata As New WDABase
Try
objdata.SQL = "usp_InsertEmployee"
objdata.InitializeCommand()
objdata.OpenConnection()
objdata.AddParameter("BirthDate", OleDb.OleDbType.Date,
8,dtBirthDate)
objdata.AddParameter("StatusDate", OleDb.OleDbType.Date,
8, dtBirthDate)
objdata.AddParameter("StartDate", OleDb.OleDbType.Date,
8,dtStartDate)
intRowsAffected = objdata.Command.ExecuteNonQuery
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
objdata.CloseConnection()
End Using
The three variables(dtBirthDate, dtStatusDate and dtStartDate) are declared as DateTime data types.
I am at a frustrated and at a complete loss as to why I keep getting the error, can someone please help.
|