我正在爲Visual Basic程序創建一個簡單的用戶ID /密碼訪問數據庫。 除了添加新用戶之外,一切都可以使用。Visual Basic 2013在Access Execure中創建新記錄錯誤
我的文本框對象被鏈接到我的數據庫,但當我嘗試添加我的新用戶時,我不斷收到此錯誤。
Error: An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
這裏是我的代碼:
Imports System.Data.OleDb
Public Class newUser
Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\PasswordCheck.accdb"
Dim conn As OleDbConnection = New OleDbConnection
Private Sub btnNewUser_Click(sender As Object, e As EventArgs) Handles btnNewUser.Click
Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\PasswordCheck.accdb"
Dim conn As OleDbConnection = New OleDbConnection
conn.ConnectionString = connString
conn.Open()
Dim SaveNew As String = "INSERT INTO [Password] (UserId, Password, firstName, LastName) Values ('" & txtUserID.Text & "','" & txtPassword.Text & "','" & txtFirst.Text & "','" & txtLast.Text & "')"
Dim cmd As New OleDbCommand
cmd.Connection = conn
With cmd
.CommandText = SaveNew
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("You have been added to our Database")
txtUserID.Text = ""
txtPassword.Text = ""
txtFirst.Text = ""
txtLast.Text = ""
conn.Close()
End Sub
Private Function SaveNew() As String
Throw New NotImplementedException
End Function
End Class
A)那是一個VB.NET代碼/錯誤不是VB6所以標記是錯誤的,b)我們需要錯誤的文本在帖子中,而不是一個錯誤圖片的鏈接c)有更多的信息詳細信息d)**不要**串聯字符串以生成SQL;使用sql參數e)密碼永遠不應該作爲純文本存儲 - 對它們進行哈希處理。 f)閱讀[問],參加[遊覽],修復標記和[編輯]帖子請 – Plutonix
我同意Plutonix所說的一切。但是,如果你堅持使用字符串連接,你會錯過變量之間的逗號 – Simon
我已經改變了標籤,並添加了逗號。我仍然得到錯誤。包含錯誤的文本爲 – Fazz1967withExplosions