Hi, sorry if this is a bit trivial but im a bit of a beginner. Im trying to write a datetime into an access database using the following code:
Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click
Dim HardwareId As String
Dim Staff As String
Dim Description As String
Dim Location As String
Dim d As DateTime = DateTime.Now
Dim Message As String
HardwareId = ListId.Text
Staff = txtStaff.Text
Description = txtDescription.Text
Location = txtLocation.Text
Try
DBCon.Open()
Dim sa As Integer
Dim DSet4 As New DataSet, SQLStr4 As String
Dim dbAdaptr4 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
With dbAdaptr4
.TableMappings.Add("Table", "Hardware_Problems")
SQLStr4 = "INSERT INTO Hardware_Problems (Hardware_Id, Date_Time, Staff_Reported, Problem_Description, Location) VALUES (@Hardware_Id, @Date_Time, @Staff_Reported, @Problem_Description, @Location)"
Dim sqlCommand As New System.Data.OleDb.OleDbCommand
sqlCommand.Connection = DBCon
sqlCommand.CommandText = SQLStr4
sqlCommand.Parameters.Add("@Hardware_Id", SqlDbType.VarChar).Value = HardwareId
sqlCommand.Parameters.Add("@Date_Time", SqlDbType.SmallDateTime).Value = d
sqlCommand.Parameters.Add("@Staff_Reported", SqlDbType.VarChar).Value = Staff
sqlCommand.Parameters.Add("@Problem_Description", SqlDbType.VarChar).Value = Description
sqlCommand.Parameters.Add("@Location", SqlDbType.VarChar).Value = Location
sa = sqlCommand.ExecuteNonQuery()
Message = ("Problem In " & Location & " Logged")
Label1.Text = Message
End With
DBCon.Close()
Catch ex As Exception
Label1.Text = "Error reading database " & ex.Message
End Try
End Sub
Insert worked before trying the datatime part however since then it keeps throwing the error:
Error reading database datatype mismatch in criteria expression.
Any help and ideas would be much appreciated thanks
johnuk4
Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click
Dim HardwareId As String
Dim Staff As String
Dim Description As String
Dim Location As String
Dim d As DateTime = DateTime.Now
Dim Message As String
HardwareId = ListId.Text
Staff = txtStaff.Text
Description = txtDescription.Text
Location = txtLocation.Text
Try
DBCon.Open()
Dim sa As Integer
Dim DSet4 As New DataSet, SQLStr4 As String
Dim dbAdaptr4 As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
With dbAdaptr4
.TableMappings.Add("Table", "Hardware_Problems")
SQLStr4 = "INSERT INTO Hardware_Problems (Hardware_Id, Date_Time, Staff_Reported, Problem_Description, Location) VALUES (@Hardware_Id, @Date_Time, @Staff_Reported, @Problem_Description, @Location)"
Dim sqlCommand As New System.Data.OleDb.OleDbCommand
sqlCommand.Connection = DBCon
sqlCommand.CommandText = SQLStr4
sqlCommand.Parameters.Add("@Hardware_Id", SqlDbType.VarChar).Value = HardwareId
sqlCommand.Parameters.Add("@Date_Time", SqlDbType.SmallDateTime).Value = d
sqlCommand.Parameters.Add("@Staff_Reported", SqlDbType.VarChar).Value = Staff
sqlCommand.Parameters.Add("@Problem_Description", SqlDbType.VarChar).Value = Description
sqlCommand.Parameters.Add("@Location", SqlDbType.VarChar).Value = Location
sa = sqlCommand.ExecuteNonQuery()
Message = ("Problem In " & Location & " Logged")
Label1.Text = Message
End With
DBCon.Close()
Catch ex As Exception
Label1.Text = "Error reading database " & ex.Message
End Try
End Sub
Insert worked before trying the datatime part however since then it keeps throwing the error:
Error reading database datatype mismatch in criteria expression.
Any help and ideas would be much appreciated thanks
johnuk4