Please help,

I have a small application which has a MS Access as backend, and the front end is developed using VB.Net 2008. When I click on the listview item and then click delete button to delete a particula list and its content on the database, it is giving me the error as "No value given for one or more required parameters". Please check my code below and help. FYI - My access database have a Primary key as the first character of the firstname combined with the first 2 characters of the lastname. It does not have a Anutonumber fiels. My code for the delete button is as follows: the code was working fine on a MS Access that has a Primary Key as the AutoNumber being generated. Thanking you in advance.

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        If lvData.SelectedIndices.Count <= 0 Then
            Return 'No selected Item so exit
        End If

        Dim ItemNo As Integer = lvData.SelectedIndices(0) 'Grab the selected index
        Try
            Dim I As Integer = MsgBox("Are you sure you want to delete this record? You can't Undo", MsgBoxStyle.YesNo, "Are you sure?")
            If I = MsgBoxResult.Yes Then

                conn.Open()
                Dim cmd2 As New OleDb.OleDbCommand("DELETE FROM tblPNGATSAExecutive WHERE ExecutiveID = " & lvData.Items(ItemNo).SubItems(0).Text, conn)
                cmd2.ExecuteNonQuery()
                MsgBox("Record removed successfully", MsgBoxStyle.OkOnly, "Remove Succeeded")

            Else
                'They didn't really want to delete, so exit
                Return 'This exits the sub
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            conn.Close()
        End Try
        RefreshLV()
    End Sub

:confused:

missing single quote :

Dim cmd2 As New OleDb.OleDbCommand("DELETE FROM tblPNGATSAExecutive WHERE ExecutiveID = '" & lvData.Items(ItemNo).SubItems(0).Text & "'", conn)

Jx_Man,

Thank you so much for you help. It worked!

I just want to ask one more question. I'm trying to learn and MASTER VB.Net but I have a problem. There are alot of classes and properties. How do you remember them and what is the trick behind mastering VB.Net language? I simply can't remember everything and even remembering is not a good way of mastering such a language; instead I must know how to work with the language to solve the problem at hand. I'm still having problem writing classes even I have read it over and over again from different sites and books. Now I just write codes behind forms and buttons only. I can't write classes or even simple modules. Please help me learn the steps to Mastering VB.Net.

Thank you....

i'm not try to remember all of it..just try to understand how to use it and do a lot of practice.
ex : delete query is from sql language. there are single quote in the statment.
delete from login where login_id = '1' , when you use it on vb you will know that delete statment still need single quote. that i mean about understanding.
if you understand automatically you'll remember it :)

Happy coding and don't forget to mark this thread as solved.

Thanks Tx_Man

You are the true VB.net man. Thanks once again.

By all means I'll try by best to understand VB.net.

MessageBox.Show("All fields Are Required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Else
                myqry = "UPDATE tblCoffee SET "
                myqry = myqry + " CName = '" & TextBoxName.Text & "',"
                myqry = myqry + " Price = '" & TextBoxPrice.Text & "',"
                myqry = myqry + " Stocks = '" & TextBoxStocks.Text & "',"
                myqry = myqry + " Weight = '" & TextBoxWeight.Text & "',"
                myqry = myqry + " Units = '" & ComboBoxUnit.Text & "',"
                myqry = myqry + " StockIn = '" & TextBoxStockIn.Text & "',"
                myqry = myqry + " StockOut = '" & TextBoxStockOut.Text & "',"
                myqry = myqry + " MinStock = '" & TextBoxMinStock.Text & "',"
                myqry = myqry + " MaxStock = '" & TextBoxMinStock.Text & "'"
                myqry = myqry + " WHERE "
                myqry = myqry + " Code = " & TextBoxCode.Text


                mycmd = New OleDbCommand(myqry, conn)
                mycmd.ExecuteNonQuery()
                Call Set1()
            End If
        End If

        Call FillListview()
        Call ClearAlltextBox()






    THE ERROR is No value given for one or more required parameters

Edited 4 Years Ago by uzumakisam: wrong

What if the value is not an integer ? what is the code for deleting listview item and also the database value..

This question has already been answered. Start a new discussion instead.