I am trying to take data from a web form and place it in an ms-access database. The code which is in the aspx.vb page (to date) is listed below but when I run it the cmd.ExecuteNonQuery() throws up
"No value given for one or more required parameters."
Why is this? What should the code read?
Protected Sub RegButton_Click(sender As Object, e As EventArgs) Handles RegButton.Click
Dim con As New OleDb.OleDbConnection
Dim cmd As New OleDb.OleDbCommand
Dim Sql As String
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Users.accdb;Persist Security Info=True"
con.Open()
Sql = "INSERT INTO Users.Personnel (FirstName, LastName, Address, Email, Username, UserPassword) VALUES (@first, @last, @addr, @email, @uname, @pwd) "
cmd = New OleDb.OleDbCommand(Sql, con)
cmd.ExecuteNonQuery()
MsgBox("saved")
cmd.Parameters.AddWithValue("@first", FirstBox.Text)
cmd.Parameters.AddWithValue("@last", LastBox.Text)
cmd.Parameters.AddWithValue("@addr", AddressBox.Text)
cmd.Parameters.AddWithValue("@email", EmailBox.Text)
cmd.Parameters.AddWithValue("@uname", UserBox.Text)
cmd.Parameters.AddWithValue("@pwd", PwdBox.Text)
con.Close()
End Sub