0

this is my code for loading the data in my database going to my datagrid

Private Sub Records_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim connString As String = "Provider=Microsoft.Ace.Oledb.12.0; Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\BackUp\Database3.Accdb;"
        Dim MyConn As OleDbConnection
        Dim da As OleDbDataAdapter
        Dim ds As DataSet
        Dim tables As DataTableCollection
        Dim source1 As New BindingSource

        MyConn = New OleDbConnection
        MyConn.ConnectionString = connString
        ds = New DataSet
        tables = ds.Tables
        da = New OleDbDataAdapter("Select * from [userinfo] ORDER BY ID", MyConn) 'Change items to your database name
        da.Fill(ds, "userinfo") 'Change items to your database name
        Dim cb = New OleDbCommandBuilder(da)
        Dim view As New DataView(tables(0))
        source1.DataSource = view
        DataGridView1.DataSource = view
    End Sub

and this is my code for deleting datagrid but it delete the whole data(i know cause i state in sql)

Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
        Dim connString As String = "Provider=Microsoft.Ace.Oledb.12.0; Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\BackUp\Database3.Accdb;"
        Dim MyConn As OleDbConnection
        Dim da As OleDbDataAdapter
        Dim ds As DataSet
        Dim tables As DataTableCollection
        Dim source1 As New BindingSource
        Dim row As New Integer

        Try

            MyConn = New OleDbConnection
            MyConn.ConnectionString = connString
            ds = New DataSet
            tables = (ds.Tables)
            da = New OleDbDataAdapter("Delete * from [userinfo]", MyConn)
            da.Fill(ds, "userinfo")

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

i want to delete selectedrow in my data grid as well in my database. thank you in advance

2
Contributors
1
Reply
5
Views
1 Year
Discussion Span
Last Post by Shark_1
0

Use oledbdatackmmand object, asign command text and execute it to delete the data row.
From my opinion you used here a wrong sql statement I.E."Delete * from [userinfo]". It should be "Delete From [userinfo] Where <condition here>".
Hope it can help you.

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.