我寫了一些代碼插入數據的形式到ms訪問數據庫 它運行成功,並沒有提供任何錯誤 但當我在數據中看到基地我發現沒有數據插入數據庫中。 有什麼問題? 所以,夥計們,請幫助我。vb.net插入命令爲ms訪問沒有顯示任何錯誤,但沒有插入到表
這裏是我的vb.net代碼:
Private Sub btnCreateUser_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateUser.Click
Dim con2 As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\OfficeAutomationSystem.accdb; Persist Security Info=False")
Dim cmd As New OleDb.OleDbCommand
If Not con2.State = ConnectionState.Open Then
con2.Open()
End If
cmd.Connection = con2
'add data to table
cmd.CommandText = "INSERT INTO tblUser(emp_id, user_id, pwd, user_type) " & _
" values(" & Me.cbEmpId.SelectedItem & ", '" & Me.txtUserId.Text & "','" & _
Me.txtPassword.Text & "', '" & Me.cbUserType.SelectedItem & "')"
cmd.ExecuteNonQuery()
MsgBox("running")
End Sub
,這裏是我的MS Access數據庫的數據庫結構:
field name dataYpe
serial_no AutoNumber
emp_id Number
user_id Text
pwd Text
user_type Text
在此先感謝。
請問這情況是有道理的。如果不con2.State = ConnectionState.Open然後con2.Open()? – DevelopmentIsMyPassion
嘗試刪除條件,只寫con2.Open(),讓我知道 – DevelopmentIsMyPassion
是的,我刪除如果codition,並存在相同的問題 –