Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27409

VS 2010 Load data in DGV based on the values using NOT IN Clause

$
0
0
Hi all,

I am trying a simple employee management system in vb.net 2010 and MS Access 2003
I have a task, In form1 their is a button and a DGV if the user click the button, list of employee names will shown in another form (say) form2 DGV with a check box column if user checks multiple rows and click ok button in form2 those rows will get in the form1 DGV and i want the form2 DGV to show only the employee list NOT IN form1 DGV
I have tried the below code but i am not able to filter the form2 DGV if form1 DGV has multiple rows.

Please help me to get out of this.

Code:

Private Sub frmEmpPickList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

With frmEmpEntry.DataGridView2
Dim codes As String
            Dim i As Int16
            For i = 0 To .RowCount - 1
                codes = frmEmpEntry.DataGridView2.Rows(i).Cells(1).Value
            Next

            Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\EmployeeDB.mdb;" & _
                                            "Jet OLEDB:Database Password=12345;"
            Dim selectCommand As String
            Dim connection As New OleDbConnection(connectionString)
            selectCommand = "SELECT EmpCode, EmpName, EmpDept FROM EmployeeMaster WHERE EmpCode NOT IN ('" & codes & "')"
               
            Me.dataAdapter = New OleDbDataAdapter(selectCommand, connection)
            Dim commandBuilder As New OleDbCommandBuilder(Me.dataAdapter)
            Dim table As New DataTable()
            Me.dataAdapter.Fill(table)
            Me.bindingSource1.DataSource = table
            Dim data As New DataSet()
            Me.DataGridView1.DataSource = Me.bindingSource1


Viewing all articles
Browse latest Browse all 27409

Trending Articles