Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
没有为一个或多个必需参数vb.net oledb提供值_Vb.net_Oledb - Fatal编程技术网

没有为一个或多个必需参数vb.net oledb提供值

没有为一个或多个必需参数vb.net oledb提供值,vb.net,oledb,Vb.net,Oledb,这将更新datagrid视图中的选定记录。但是,当我单击“保存更改”按钮时,会出现一个错误;“一个或多个参数没有给定值。”知道如何解决这个问题吗?使用cmd.parameters.AddWithValue而不是cmd.parameters.Add Public Class ViewPhoneRecords Dim con As New OleDb.OleDbConnection Dim dbProvider As String Dim dbSource As String Dim da As O

这将更新datagrid视图中的选定记录。但是,当我单击“保存更改”按钮时,会出现一个错误;“一个或多个参数没有给定值。”知道如何解决这个问题吗?

使用
cmd.parameters.AddWithValue
而不是
cmd.parameters.Add

Public Class ViewPhoneRecords
Dim con As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim da As OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim sqlquery As New OleDb.OleDbCommand
Dim con1 As New OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database.accdb")

Private Sub SaveBtn_Click(sender As Object, e As EventArgs) Handles SaveBtn.Click


    Dim sqlupdate As String
    ' Here we use the UPDATE Statement to update the information. To be sure we are 
    ' updating the right record we also use the WHERE clause to be sureno information
    ' is added or changed in the other records
    sqlupdate = "UPDATE PhoneRecords SET Forename=@Forename, Surname=@Surname, Address=@Address, PhoneModel=@PhoneModel, PhoneNumber=@PhoneNumber, Postcode=@Postcode WHERE IDNum='" & IDTextBox.Text & "'"
    Dim cmd As New OleDbCommand(sqlupdate, con1)
    ' This assigns the values for our columns in the DataBase. 
    ' To ensure the correct values are written to the correct column

    cmd.Parameters.Add(New OleDbParameter("@Forename", ForenameTextBox1.Text))
    cmd.Parameters.Add(New OleDbParameter("@Surname", SurnameTextBox1.Text))
    cmd.Parameters.Add(New OleDbParameter("@Address", AddressTextBox1.Text))
    cmd.Parameters.Add(New OleDbParameter("@PhoneModel", PhoneModelTextBox1.Text))
    cmd.Parameters.Add(New OleDbParameter("@PhoneNumber", PhoneNumberTextBox1.Text))
    cmd.Parameters.Add(New OleDbParameter("@Postcode", PostcodeTextBox1.Text))

    con1.Open()
    cmd.ExecuteNonQuery()

    MsgBox("Row(s) Inserted !! ") 'Displays message box informing the user that the database has been added to

    con1.Close() 'Connection closed
    Me.Refresh()
End Sub