954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Delete Highlighted /Selected in Adodc DataGrid

can u help me about this

Attachments Untitled-2.jpg 15.8KB
Shodow
Junior Poster
115 posts since Jan 2011
Reputation Points: 14
Solved Threads: 0
 

DataGridView1.Rows.RemoveAt(DataGridView1.CurrentRow.Index)

Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 

runtime error

Shodow
Junior Poster
115 posts since Jan 2011
Reputation Points: 14
Solved Threads: 0
 

Can you please paste your code here? so that we can help..

Pgmer
Master Poster
714 posts since Apr 2008
Reputation Points: 54
Solved Threads: 121
 
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
great_mind
Newbie Poster
1 post since Apr 2011
Reputation Points: 10
Solved Threads: 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)

neket
Newbie Poster
4 posts since Feb 2007
Reputation Points: 10
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: