Script pencarian di datab grid dgn databinding


Public Class Form2

    Dim con As New OleDb.OleDbConnection
    Dim cmdOle As New OleDb.OleDbCommand
    Dim dsOle As New DataSet
    Dim da As New OleDb.OleDbDataAdapter
    Dim dtOle As New DataTable
    Dim sql As String

    Private Sub LoadData()
        con.ConnectionString = ("Provider = Microsoft.JET.OLEDB.4.0;Data Source= D:\vb\Struct\DATA_master.mdb")
        Try

            cmdOle = con.CreateCommand
            cmdOle.CommandText = "SELECT * FROM `MASTER PERUSAHAAN` where NO_P LIKE '%" & Trim(txtSearchKey.Text) & "%'"
            da.SelectCommand = cmdOle
            da.Fill(dsOle, "NO_P") ' This Table name

            da.SelectCommand = cmdOle
            da.Fill(dsOle, "NO_P") ' This Table Name
            MASTER_PERDataGridView.DataSource = dsOle
            MASTER_PERDataGridView.DataMember = "NO_P"
            MASTER_PERDataGridView.ReadOnly = True

            'dgAuthor.DataSource = dsOle
            'dgAuthor.DataMember = "NO_P" ' This table Name
            'dgAuthor.ReadOnly = True
        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Koneksi Error !!")
        End Try
    End Sub
 

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DATA_masterDataSet.MASTER_PER' table. You can move, or remove it, as needed.
        Me.MASTER_PERTableAdapter.Fill(Me.DATA_masterDataSet.MASTER_PER)
        LoadData()
    End Sub

    Private Sub MASTER_PERBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MASTER_PERBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.MASTER_PERBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DATA_masterDataSet)
    End Sub

    Private Sub MASTER_PERDataGridView_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles MASTER_PERDataGridView.CellContentClick
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        con.ConnectionString = ("Provider = Microsoft.JET.OLEDB.4.0;Data Source= D:\vb\Struct\DATA_master.mdb")
        Try
            dsOle.Clear()
            dtOle.Clear()
            cmdOle = con.CreateCommand
            cmdOle.CommandText = "SELECT * FROM `MASTER PERUSAHAAN` where NO_P LIKE '%" & Trim(txtSearchKey.Text) & "%'"
            da.SelectCommand = cmdOle
            da.Fill(dsOle, "NO_P") ' This Table name

            MASTER_PERDataGridView.DataSource = dsOle
            MASTER_PERDataGridView.DataMember = "NO_P"
            MASTER_PERDataGridView.ReadOnly = True
        Catch ex As Exception
            MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Koneksi Error !!")
        End Try
    End Sub

    Private Function dgAuthor() As Object
        Throw New NotImplementedException
    End Function
End Class

No comments:

Post a Comment