0

Can anyone tell me what's wrong with this code? It's giving me an error in cmd.ExecuteNonQuery()

Protected Sub btnCreateAccount_Click(sender As Object, e As System.EventArgs) Handles btnCreateAccount.Click

    Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Brian\Documents\Visual Studio 2010\WebSites\WebSite3\db.mdb;")

    Dim cmd As OleDbCommand = New OleDbCommand("INSERT INTO [User] (CustomerName, CustomerSurname, Address, Country, TelNo, Username, Password, UserTypeID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", conn)




    If txtPass.Text = txtCPass.Text Then

        conn.Open()


        cmd.Parameters.Add("@CustomerName", OleDbType.VarChar, 255).Value = txtName.Text
        cmd.Parameters.Add("@CustomerSurname", OleDbType.VarChar, 255).Value = txtSurname.Text
        cmd.Parameters.Add("@Address", OleDbType.VarChar, 255).Value = txtAddress.Text
        cmd.Parameters.Add("@Country", OleDbType.VarChar, 255).Value = txtCountry.Text
        cmd.Parameters.Add("@TelNo", OleDbType.Integer).Value = txtTelNo.Text
        cmd.Parameters.Add("@Username", OleDbType.VarChar, 255).Value = txtUsername.Text
        cmd.Parameters.Add("@Password", OleDbType.VarChar, 255).Value = txtPass.Text
        cmd.Parameters.Add("@UserTypeID", OleDbType.Integer, 255).Value = "1"





        cmd.ExecuteNonQuery()

        conn.Close()
        lblAccount.Visible = True



    End If

End Sub

End Class

3
  • It's telling me there's an error in the "INSERT INTO" statement. But I tried it previously, and it was working. All I did was change the column's names in the db and then in asp.net Commented Mar 25, 2012 at 14:16
  • Can you run the command by hand. Is there a constraint issue or a column that must be unique. Commented Mar 25, 2012 at 14:17
  • There's the 'UserID' which is an autonumber through the ms-access db Commented Mar 25, 2012 at 14:20

1 Answer 1

1

EDIT: It's probably that username and password are reserved keywords in Access.

Try to surround them with brackets:

 ..., TelNo, [Username], [Password], ...
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.