好的,首先嘿。使用Visual Basic SQL訪問更新
技術上我是新來這個網站,但我一直在使用它作爲幾年的資源,而這只是因爲我很爲難,我現在就需要你的援助。
我有一個VB腳本被查詢數據庫,以字符串填充預期框和顯示它。
我的問題是,當我嘗試使用更新SQL命令,它完成但它不更新當我手動檢查數據庫。
Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Data.mdb';")
Dim da As New OleDbDataAdapter
Dim dt As New DataTable()
Dim cmd As New OleDbCommand
da.SelectCommand = New OleDbCommand("update FDSL set [email protected], [email protected] where ID = @ID", con)
Dim paramID As New OleDbParameter
paramID.ParameterName() = "@ID"
paramID.Value() = Label8.Text
da.SelectCommand.Parameters.Add(paramID)
Dim paramHost As New OleDbParameter
paramHost.ParameterName() = "@Host"
paramHost.Value() = TextBox1.Text
da.SelectCommand.Parameters.Add(paramHost)
Dim paramOwn As New OleDbParameter
paramOwn.ParameterName() = "@Owner"
paramOwn.Value() = TextBox4.Text
da.SelectCommand.ExecuteNonQuery()
MessageBox.Show("Record Updated! ", "Update Status", MessageBoxButtons.OK, MessageBoxIcon.Information)
Refresh()
con.Close()
我已經嘗試了在末端使用.tostring的參數,但是這也不起作用。
---------- ----------------解決
我必須感謝@Gord湯普森的這些援助,但我解決了這個問題通過重新編碼它。
Dim str As String
str = "update FDSL set [email protected], [email protected] where [email protected]"
Dim cmd As New OleDbCommand(str, con)
cmd.Parameters.AddWithValue("@Hostname", TextBox1.Text)
cmd.Parameters.AddWithValue("@Owner", TextBox2.Text)
cmd.Parameters.AddWithValue("@ID", textbox6.Text)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
這現在可以正常工作了,謝謝你的幫助!
高興地看到,你得到它整理出來。我正要用一些簡化的代碼編輯我的答案,但看起來和你的一樣。 –