淨,我試圖插入數據到訪問數據庫使用SQL,我有下面的代碼,當我嘗試執行,它會提示我一個錯誤消息,並突出顯示con.open()我不明白爲什麼它不工作,任何人都可以指導我。謝謝VB.NET SQL訪問插入語句
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles AddBut.Click
Dim dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source= c:\Databse\Company_db.accdb"
Dim dbSource = "Data Source= C:\Databse\Company_db.accdb"
Dim empNum As String
Dim empFname As String
Dim empLname As String
Dim empDept As String
Dim empStat As String
Dim empYears As String
empNum = eNumText.Text
empFname = empFnameText.Text
empLname = empLnameText.Text
empDept = Deptd.Text
empStat = Statd.Text
empYears = yearstext.Text
Dim sql = "INSERT INTO tbl_empinfo (EmpID, FirstName, LastName, Department, Status, Years " & _
") " & _
"Values(empNum, empFname, empLname, empDept, empStat, empYears)"
con.ConnectionString = dbProvider & dbSource
Using cmd = New OleDb.OleDbCommand(sql, con)
con.Open()
cmd.Parameters.AddWithValue("EmpID", empNum)
cmd.Parameters.AddWithValue("FirstName", empFname)
cmd.Parameters.AddWithValue("LastName", empLname)
cmd.Parameters.AddWithValue("Department", empDept)
cmd.Parameters.AddWithValue("Status", empStat)
cmd.Parameters.AddWithValue("Years", empYears)
cmd.ExecuteNonQuery()
End Using
con.Close()
End Sub
你拼錯了C:\ Databse \?也許C:\ Database \ – Fionnuala
@Remou nope這真的就是我的文件夾的名字:( – user3476579