0

Hi all,
I was having a huge problem,i mean i spent days trying to fix it but i get the same exception everytime when i run the app.
here's the thing i have a record that is loaded from the database using the listview.it works perfect for the insertion part.but when i try to delete a certain row it gives me the previous exception.
so please if one of you could give me a precious solution
thankyou all

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim str As String
        Dim conn As OleDbConnection = GetDbConnection()
        Dim cmd As OleDbCommand
        Dim selectedItem As Integer = ListView1.SelectedIndices(0)
        str = "DELETE FROM AdigratT WHERE Bridge_Number = '" & ListView1.Items(selectedItem).SubItems(0).Text & "'"
        cmd = New OleDbCommand(str, conn)
        cmd.ExecuteNonQuery()
        MsgBox("Record Removed Successfully")
        conn.Close()
    End Sub
4
Contributors
12
Replies
40
Views
3 Years
Discussion Span
Last Post by Begginnerdev
Featured Replies
  • Hey Begginnerdev,it definitely worked.I really really appreciate your work,you got a magic fingers Read More

0

Try :
str = "DELETE FROM AdigratT WHERE Bridge_Number = '" & ListView1.Items(x).SubItems(0).Text & "'"

0

It still does not work Jx.it's like replacing the declared variable selectedItem with x right?

0

when i try to delete a certain row it gives me the previous exception

What previous exception?

Is Bridge_Number a Text field? If not, get rid of the single qotes around it in the query. What column index does Bridge_Number represent in the listview? Your query indicates that it is the first column.

0

It still does not work Jx.it's like replacing the declared variable selectedItem with x right?

Ah..I didn't realized it but the code works fine to me.
What errors is came up?

Also you can try change his :
Dim selectedItem As Integer = ListView1.SelectedItems(0).Index
or
Dim selectedItem As Integer = ListView1.SelectedIndices.Item(0)

Edited by Jx_Man

0

'No Value given for one or more required parameters' exception is being thrown.
and also i've tried it with the following code,still doesn't work.

Dim bridgenumber As String
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        Dim conn As OleDbConnection = GetDbConnection()
        Dim cmd As OleDbCommand
        bridgenumber = TextBox1.Text.ToString()
        cmd = New OleDbCommand("DELETE FROM AdigratT WHERE Bridge Number = '" & bridgenumber & "'", conn)
        cmd.ExecuteNonQuery()
        MsgBox("Record Removed Successfully")
        conn.Close()
    End Sub
0

Maybe if it's possible ii can give you the source code and have a look at it

0

I suspect the "Bridge Number" part of your query.

You may have to wrap your field name with [ brakets.

For example:

cmd = New OleDBCommand("DELETE FROM Adigrat WHERE [Bridge Number]=@BridgeNumber",conn)
cmd.Parameters.AddWithValue("@BridgeNumber",bridgenumber)

cmd.ExecuteNonQuery()
1

Hey Begginnerdev,it definitely worked.I really really appreciate your work,you got a magic fingers

Votes + Comments
Congrats!
0

Hi again Begginerde,
Can i use the same code for the update scenario,i had the same problem with the update code
i've posted the code on the beginning of the discussion

0

An update statement would look something like this:

cmd = New OleDBCommand("UPDATE Adigrat SET [Bridge Number]=@Value",con)
cmd.Parameters.AddWithValue("@Value",ValueToUpdate)

cmd.ExecuteNonQuery()
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.