Link to home
Start Free TrialLog in
Avatar of MBHEY131
MBHEY131

asked on

"DATABASE" DATAVIEW GRID

Here's the first part of my code:
Private Sub frmCust_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim oledbDA As System.Data.OleDb.OleDbDataAdapter
        Dim oleFillComm As System.Data.OleDb.OleDbCommand
        Dim oleUpdComm As System.Data.OleDb.OleDbCommand
        Dim oleDS As DataSet
        Dim oleBS As BindingSource

        oleFillComm = New System.Data.OleDb.OleDbCommand
        oleUpdComm = New System.Data.OleDb.OleDbCommand
        oleDS = New DataSet

        oleconn = New System.Data.OleDb.OleDbConnection
        oledbDA = New System.Data.OleDb.OleDbDataAdapter
        oleconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=C:\ShopHand\ShopHand\ShopHand\slspro.mdb;" & _
            "Persist Security Info=True"
        oleconn.Open()

        oleFillComm.Connection = oleconn
        oleFillComm.CommandText = "SELECT         LastName, FirstName, MiddleInitial, Address1, Address2, City, State, Zip, " & _
        "WorkPhone, CellPhone, HomePhone, Fax, EmailAddress, IsEmployee, Notes, PayrollDeduction, SocialSecurity, " & _
        "Deals.LocalLenderAppID, Deals.FundingStatus, Deals.FundingDate, Deals.LastWriteCount " & _ 
"FROM            ((Customers INNER JOIN " & _
                         "Stock ON Customers.CustomerID = Stock.PurchasedFrom) INNER JOIN " & _
                         "Deals ON Stock.InventoryID = Deals.VehicleSold) " & _
"ORDER BY Customers.LastName"

        oledbDA.SelectCommand = oleFillComm
        oledbDA.Fill(oleDS)

        Me.DataGridView1.DataSource = oleDS.Tables(0)

    End Sub

Open in new window


The above code loads a "datagridview1" from a database by way of a dataset (oleDS) which works fine.

    Public Function FindCust(ByVal CustText As String) As Boolean

        Dim TypeOfForm As String = "r"
        Dim IsOpened As Boolean = False
        Dim cform As frmCust = Nothing

        Call Get_Custform(cform)

        Call SeeIfFormHasAnInstanceOpened(TypeOfForm, IsOpened)
        If IsOpened = True Then
        Else
            MessageBox.Show("Customer Form Not Opened - OPEN FORM", "Form Not Opened", MessageBoxButtons.OK)
            FindCust = False
            Return FindCust
            Exit Function
        End If

        cform.DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect

        Dim intcount As Integer = 0
        Dim CellToLookIn As Integer = 0
        Dim rowindex As String = Nothing

        cform.lblTxtToFind.Visible = False
        If IsNothing(cform.cboFind.SelectedItem) Then
        Else
            If cform.cboFind.SelectedItem = "Last Name" Then
                CellToLookIn = 0
            Else
                CellToLookIn = 15
            End If
        End If

        cform.DataGridView1.AllowUserToAddRows = False
        For Each row As DataGridViewRow In cform.DataGridView1.Rows
            If cform.DataGridView1.Rows(intcount).Cells(CellToLookIn).Value.ToString = CustText Then
                cform.DataGridView1.Rows(intcount).Selected = True
                FindCust = True
                Exit Function
            End If
            intcount = intcount + 1
        Next
        cform.DataGridView1.AllowUserToAddRows = True
        FindCust = False
        Return FindCust
    End Function

Open in new window


the above code is a procedure getting called when the customer searches the data for a "Last Name" or "VIN" of a dataset record
which also works fine - I guess my ? is - When the data is  found I need a way for the screen to go to the (SELECTED RECORD) like a bindingsource so I can call the .MOVENEXT method as the code loops through the data and I don't know now to make a binding source in code! Could someone help me?
ASKER CERTIFIED SOLUTION
Avatar of MBHEY131
MBHEY131

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial