2016-09-19 220 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 
相關問題