2016-09-19 225 views
0

我试图使用UPDATE命令更新我的记录。我得到这个错误:使用“UPDATE”命令时,没有给出一个或多个必需参数的值

No value given for one or more required parameters.

这里是我的代码:

Private Sub saveOle_Click(sender As Object, e As EventArgs) Handles saveOle.Click 
    Try 
     Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\samplelangtowalangya.mdb;") 
      conn.Open() 
      Dim command As New OleDbCommand("UPDATE sample SET ewan = @ewan, ko = @ko, sayo = @sayo, hehehe = @hehehe WHERE Number_of_Employees = @Number_of_Employees", conn) 
      With command.Parameters 
       .AddWithValue("@ewan", ewan.Text) 
       .AddWithValue("@ko", ko.Text) 
       .AddWithValue("@sayo", sayo.Text) 
       .AddWithValue("@hehehe", hehehe.Text) 
       command.ExecuteNonQuery() 
      End With 

      MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information) 
      command.Dispose() 
      conn.Close() 
     End Using 
    Catch ex As Exception 
     MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error) 
    End Try 
End Sub 

Number_of_Employees是我的ID和主键。

+1

的SQL有5个命名参数,你只提供4.您需要为命名提供一个值where子句中的值还是结果SQL的外观? –

+0

哦,是的。我试图在'@ ewan'之前先放置我的'ID'。我把它放在四个领域之后。它现在有效,谢谢:) – wwwMarvsdotcom

回答

0

于是,我就放在我的四个字段ID后,现在工作得很好:)

Private Sub saveOle_Click(sender As Object, e As EventArgs) Handles saveOle.Click 
    Try 
     Using conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\samplelangtowalangya.mdb;") 
      conn.Open() 
      Dim command As New OleDbCommand("UPDATE sample SET ewan = @ewan, ko = @ko, sayo = @sayo, hehehe = @hehehe WHERE Number_of_Employees = @Number_of_Employees", conn) 
      With command.Parameters 
       .AddWithValue("@ewan", ewan.Text) 
       .AddWithValue("@ko", ko.Text) 
       .AddWithValue("@sayo", sayo.Text) 
       .AddWithValue("@hehehe", hehehe.Text) 
       .AddWithValue("@Number_of_Employees", IDtext.Text) 
      End With 
      command.ExecuteNonQuery() 
      MessageBox.Show("Employee's Informations Successfuly Updated!", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information) 
      command.Dispose() 
      conn.Close() 
     End Using 
    Catch ex As Exception 
     MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error) 
    End Try 
End Sub 
相关问题