我想使用vb将新用户添加到访问数据库中,但是当我执行它时,它一直说错误的插入语法。任何人都可以告诉我它有什么问题吗?香港专业教育学院搜索错误,我认为代码没有错。请帮帮我
Imports System.IO
Imports System.Data.OleDb
Public Class Adduser
Private Sub createbtn_Click(sender As Object, e As EventArgs) Handles createbtn.Click
If required() = True Then
Return
End If
Dim connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Gio\Documents\Visual Studio 2012\Projects\CSS\CSS\bin\Debug\CSS.accdb;")
Try
If connection.State = ConnectionState.Closed Then connection.Open()
Dim sql As String = "insert into User(Names,Username,Password,isAdmin) values (@Names, @Username, @Password, False)"
Dim command As OleDbCommand = New OleDbCommand(sql, connection)
Dim isAdmin As Boolean
Dim Names As OleDbParameter = New OleDbParameter("@Names", OleDbType.VarWChar, 50)
Names.Value = namebox.Text.ToString()
command.Parameters.Add(Names)
Dim Username As OleDbParameter = New OleDbParameter("@Username", OleDbType.VarWChar, 50)
Username.Value = unamebox.Text.ToString()
command.Parameters.Add(Username)
Dim Password As OleDbParameter = New OleDbParameter("@Password", OleDbType.VarWChar, 50)
Password.Value = namebox.Text.ToString()
command.Parameters.Add(Password)
command.Parameters.AddWithValue("@isAdmin", isAdmin)
isAdmin = False
If command.ExecuteNonQuery() Then
connection.Close()
MessageBox.Show("New user is added!")
namebox.Text = ""
unamebox.Text = ""
passbox.Text = ""
Else
MsgBox("Addition of new user failed!")
End If
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "Data Error")
Exit Sub
End Try
End Sub