尝试
Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Jen\Documents\Jade\vb\database.accdb")
txtStatus.Text = "Active"
Dim account As String = ("Insert into Login(Username, Password, FirstName, LastName, AccountType, Status) VALUES ('" & txtUsername.Text & "' , '" & txtPass.Text & "', '" & txtFirst.Text & "', '" & txtLast.Text & "', '" & cmbType.Text & "', '" & txtStatus.Text & "')'")
conn.Open()
ole = New OleDbCommand(account, conn)
ole.ExecuteNonQuery()
MsgBox("Successfully Inserted!")
Dim strsql2 As New OleDbCommand("select * from Login", conn)
Dim sqlda = New OleDbDataAdapter(strsql2)
Dim sqldataset = New DataSet
sqlda.Fill(sqldataset)
Me.DataGridView1.DataSource = sqldataset.Tables(0)
conn.Close()
DataGridView1.Refresh()
错误显示我的insert into语句不正确。我已经多次检查我的数据库并重新键入代码但仍然得到相同的错误。
答案 0 :(得分:0)
我在查询中关闭括号后发现了一个额外的(')qoute。使用此查询和检查
Dim account As String = ("Insert into Login(Username, Password, FirstName, LastName, AccountType, Status) VALUES ('" & txtUsername.Text & "' , '" & txtPass.Text & "', '" & txtFirst.Text & "', '" & txtLast.Text & "', '" & cmbType.Text & "', '" & txtStatus.Text & "')")
希望这会有所帮助。
答案 1 :(得分:0)
AccountType和Status字符串是否类型?
如果不是你应该写这个:
Dim account As String = ("Insert into Login(Username, Password, FirstName, LastName, AccountType, Status) VALUES ('" & txtUsername.Text & "' , '" & txtPass.Text & "', '" & txtFirst.Text & "', '" & txtLast.Text & "', " & cmbType.Text & ", " & txtStatus.Text & ")'")