CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2010
    Posts
    3

    Question Moving to Current Record in Data grid

    Friends I m workin on vb.net ado.net oledb, I have also added datagrid Control to my form

    for retriving database from .Mdb file i used following code
    Code:
    'decleared Name Space
    Imports System.Data.OleDb
    
    
       'Dicleared Variabls in Class  Form1 
    
        Dim con As New OleDb.OleDbConnection
    
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim sql As String
        Dim inc As Integer
        Dim MaxRows As Integer
    
    
           'created Navigate Records() 'class
            txtSno.Text = ds.Tables("SLAPhonebook").Rows(inc).Item("SNo")
            txtName.Text = ds.Tables("SLAPhonebook").Rows(inc).Item("Name")
            txtLastName.Text = ds.Tables("SLAPhonebook").Rows(inc).Item("LastName")
            txtOrganization.Text = ds.Tables("SLAPhonebook").Rows(inc).Item("Organization")
    ' and so on...
    
          ' on form load () event i put following coding
           con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=D:\SLAPhonebook.mdb"
            sql = "Select * From sla"
            da = New OleDb.OleDbDataAdapter(sql, con)
            da.Fill(ds, "SLAPhonebook")
            MaxRows = ds.Tables("SLAPhonebook").Rows.Count
             inc = -1
    
    
           ' here i connected all text boxes to '0' row of ds.tables(rows) to show first row, as follows
    
    
            txtSno.Text = ds.Tables("SLAPhonebook").Rows(0).Item("SNo")
            txtName.Text = ds.Tables("SLAPhonebook").Rows(0).Item("Name")
            txtLastName.Text = ds.Tables("SLAPhonebook").Rows(0).Item("LastName")
    
    
           'here in formload event i also binded data grid with dataset 
           DataGrid1.SetDataBinding(ds, "sla")
           DataGrid1.DataSource = ds.Tables(0)
    'friends every thing is working fine, but when i click to move next record in table, it moves but only in text boxes which i connected with dataset.tables(rows), i want to datagrid to also move to next record as soon as i press next record button

    ' I used following code for "next Record Button", to move on next record
    Code:
            if inc <> MaxRows - 1 Then
                inc = inc + 1
                NavigateRecords()
            Else
                MsgBox("No More Rows")
    
            End If
    
            DataGrid1.DataSource = ds.Tables(inc)
            DataGrid1.SetDataBinding(ds, "sla")
    Please Help My with My Question how to move current record in datagrid, i mean when i press Next record button then datagrid's data (table) also should move to next record


    or when i click any record in datagrid, then the current record of dataset also should move to clicked record of datagrid, so that i also may see datagrid's clicked record in textboxes

    in short i want to use default feature of vb6's ado control, when we bind datagrid with ado control, it worked autometically, both data grid and adodc wer connected each other at a time, so that moving next record also apears in datagrid. please help me in my question, i m new to .net i need ur help
    Last edited by Cimperiali; March 13th, 2010 at 04:25 PM. Reason: added a couple of Code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Moving to Current Record in Data grid

    Here's a link. Download, and study! here
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Mar 2010
    Posts
    3

    Resolved Re: Moving to Current Record in Data grid

    Dear Thanks for Sending Me a Good link, but dear it seems that it covers SQL Server, while i m working on Access Database (.mdb) yes but Still I m Studying it, I Need just a few Hints from you, can u plz Help,


    I Solved my Above mentioned Problem with "Moving to Current Record in Data Grid" Because I M using now DataTable instead of Dataset.

    its Working Nice, i m now able to move between records as well as search specific record from table

    Here I need Help with Adding, Deleting and Updating Record, can u please Help me in this case or can provide any sort of links or tutorials so that i can add, delete and update record in my datatable, Yes I Have Founded Many samples but all are working with dataset, i need specific code for my Datatable Functions.
    Please help I m new to .net

  4. #4
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Moving to Current Record in Data grid

    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Moving to Current Record in Data grid

    They have examples of both. You can just change the CONNECTION STRING to change from different systems

    SQL is SQL (for the most part)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Jul 2011
    Posts
    9

    Re: Moving to Current Record in Data grid

    Hello

    Thanks for giving resources, these helps me a lot.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured