4
Contributors
5
Replies
10
Views
6 Years
Discussion Span
Last Post by neket
0
Private Sub Deletebutton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        con.Open()
        Dim sqlDeleteItem As String
        Dim a As Integer
        Dim db As SqlCommand
        Dim answer As Integer

        a = DataGridView1.Item(0, DataGridView1.CurrentRow.Index).Value
        answer = MsgBox("Do you want to delete the User?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "")
        If answer = vbYes Then
            sqlDeleteItem = "delete from Users where User_id = " & a & ""
            db = New SqlCommand(sqlDeleteItem, con)
            db.ExecuteNonQuery()
            MsgBox("User Deleted!", MsgBoxStyle.Information, "")
            ds.Clear()
            da = New SqlDataAdapter("Select * from Users", con)
            da.Fill(ds, "Users")
            DataGridView1.DataSource = ds.Tables("Users").DefaultView
        Else
        End If
        con.Close()
    End Sub

Edited by Nick Evan: Added [CODE] tags

0

Hi,

I am not familiar with DataGrid with vb, and i use ListView a lot of times.

maybe you can adopt this code and can give you an idea how to delete selected record.

sql "DELETE * FROM tblpwd where modusername = '" & lstUsers.SelectedItem.Text & "' "
lstUsers.ListItems.Remove (lstUsers.SelectedItem.Index)

This topic has been dead for over six months. 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.