Encounter problem when I am delete a record
-
Dear ALL, I have encounter problem when I deleting a record in my program. Error msg as follow: OleDbException was unhandled. No value given for one or more required parameters. I think I have declare the correct statement but it still prompt me... My code as follow: Public Sub delRec(ByVal column As String, ByVal table As String, ByVal value As String) 'create connection instance with connection string Dim myConnection As New OleDbConnection(ConnString) 'sql delete query Dim query As String If table = "SALPASS" Then query = "DELETE FROM " & table & " where " + column + " = " + value Else query = "DELETE FROM " & table & " where " & column & " = " & value End If 'create sql command instance with the delete query Dim myCommand As New OleDbCommand(query, myConnection) 'open database connection myConnection.Open() 'execute sql delete command found in query string myCommand.ExecuteNonQuery() 'Close the connection myConnection.Close() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If GroupBox1.Text = "Sales" Then If TextBox1.Text = "" Then 'display error message box MsgBox("Error!" + vbCrLf + vbCrLf + "Please select User Id to delete", MsgBoxStyle.Exclamation, "Deletion Error") Else 'deletes record from database delRec("USER_ID", "SALPASS", TextBox1.Text) lblLabel.Text = "Record Deleted" 'refresh table getsaltable() End If end sub I just want to delete the user id and password. Please advise. Thanks Jack:confused: Jack
-
Dear ALL, I have encounter problem when I deleting a record in my program. Error msg as follow: OleDbException was unhandled. No value given for one or more required parameters. I think I have declare the correct statement but it still prompt me... My code as follow: Public Sub delRec(ByVal column As String, ByVal table As String, ByVal value As String) 'create connection instance with connection string Dim myConnection As New OleDbConnection(ConnString) 'sql delete query Dim query As String If table = "SALPASS" Then query = "DELETE FROM " & table & " where " + column + " = " + value Else query = "DELETE FROM " & table & " where " & column & " = " & value End If 'create sql command instance with the delete query Dim myCommand As New OleDbCommand(query, myConnection) 'open database connection myConnection.Open() 'execute sql delete command found in query string myCommand.ExecuteNonQuery() 'Close the connection myConnection.Close() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If GroupBox1.Text = "Sales" Then If TextBox1.Text = "" Then 'display error message box MsgBox("Error!" + vbCrLf + vbCrLf + "Please select User Id to delete", MsgBoxStyle.Exclamation, "Deletion Error") Else 'deletes record from database delRec("USER_ID", "SALPASS", TextBox1.Text) lblLabel.Text = "Record Deleted" 'refresh table getsaltable() End If end sub I just want to delete the user id and password. Please advise. Thanks Jack:confused: Jack
Do one thing. the query you build in the function. Copy that Query and run that directly in the SQL Query analyzer or what ever the database you are using. this will clear you that the query is fine. Also check on which line it creates the problem ?
-
Dear ALL, I have encounter problem when I deleting a record in my program. Error msg as follow: OleDbException was unhandled. No value given for one or more required parameters. I think I have declare the correct statement but it still prompt me... My code as follow: Public Sub delRec(ByVal column As String, ByVal table As String, ByVal value As String) 'create connection instance with connection string Dim myConnection As New OleDbConnection(ConnString) 'sql delete query Dim query As String If table = "SALPASS" Then query = "DELETE FROM " & table & " where " + column + " = " + value Else query = "DELETE FROM " & table & " where " & column & " = " & value End If 'create sql command instance with the delete query Dim myCommand As New OleDbCommand(query, myConnection) 'open database connection myConnection.Open() 'execute sql delete command found in query string myCommand.ExecuteNonQuery() 'Close the connection myConnection.Close() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If GroupBox1.Text = "Sales" Then If TextBox1.Text = "" Then 'display error message box MsgBox("Error!" + vbCrLf + vbCrLf + "Please select User Id to delete", MsgBoxStyle.Exclamation, "Deletion Error") Else 'deletes record from database delRec("USER_ID", "SALPASS", TextBox1.Text) lblLabel.Text = "Record Deleted" 'refresh table getsaltable() End If end sub I just want to delete the user id and password. Please advise. Thanks Jack:confused: Jack
-
ur query i think is somewhat wrong. It should be query="DELETE FROM '"& table &"' where '" + column + "' = '" + value+"' format should be =" from '"++"' " all runtime values should be entered inthis format '"++"' if + sign doesn't work try &
:)Thanks Will try on that jack