0

Hi I've searched all over the internet for this but can't find anything useful. I have form which a user fills out and then inserts in access database. But I also have a field DateTime in my table which I want to automatically save the current date and time in the database. How do I do this? Thank you. I keep getting an error saying "an oledbparameter with parameter name '@datetime' is not contained by this oledb"

        Try
            con.Open()

            With cmd
                .Connection = con
                .CommandType = CommandType.Text
                .CommandText = "INSERT INTO tJ (S, T, DateTime) VALUES (@S, @T, @DateTime)"

                .Parameters.Add(New System.Data.OleDb.OleDbParameter("@S", System.Data.OleDb.OleDbType.VarChar, 255, Me.cmbN.Text))
                .Parameters.Add(New System.Data.OleDb.OleDbParameter("@T", System.Data.OleDb.OleDbType.VarChar, 255, Me.cmbT.Text))
                .Parameters.Add(New System.Data.OleDb.OleDbParameter("DateTime", System.Data.OleDb.OleDbType.Date))

                cmd.Parameters("@S").Value = Me.cmbN.Text
                cmd.Parameters("@T").Value = Me.cmbT.Text
                cmd.Parameters("@DateTime").Value = Date.Now

                cmd.ExecuteNonQuery()
                MsgBox("saved.", MsgBoxStyle.Information)
2
Contributors
1
Reply
15
Views
2 Years
Discussion Span
Last Post by Shark_1
0

New System.Data.OleDb.OleDbParameter("DateTime",

This is the cause for your exception. Write Parameters properly.
You can use the datatype as OleDb.OleDbType.DBTimeStamp.
And also you can declare the parameters more consizely. Like

.Parameters.Add("@S", System.Data.OleDb.OleDbType.VarChar, 255).Value = Me.cmbN.Text
.Parameters.Add("@T", System.Data.OleDb.OleDbType.VarChar, 255).Value = Me.cmbT.Text
.Parameters.Add("@DateTime", System.Data.OleDb.OleDbType.DBTimeStamp).Value = Date.Now()

Edited by Shark_1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.