You must Sign In to post a response.
  • Category: .NET

    Navigating through records using dataset

    The forum thread has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this thread.
    This thread will be reviewed shortly.
    If you think this thread contain inappropriate content, please report to webmaster.
    Hi

    I am using a dataset, which gets populated with the "emp" table (has 3 columns) data, using a dataadapter. I have a form which has 3 text boxes, I want to display the record contents into these textboxes, one record at a time. I am not using datatables. I have 4 buttons "movefirst","movenext","moveprevious" & "movelast". I should be able to navigate as per these buttons clicks
  • #4453
    You can't Directly move like vb

    You can use the following logic for moving the records
    dim intPosition as integer=0
    Next Button event just write the following code
    intPosition = intPosition + 1
    If intPosition < ds.Tables(0).Rows.Count Then
    DispData()
    Else
    intPosition = intPosition - 1
    End If
    Previous
    intPosition = intPosition - 1
    If intPosition >= 0 Then
    DispData()
    Else
    intPosition = intPosition + 1
    End If

    First
    intPosition = 0
    If intPosition >= 0 Then
    DispData()
    Else
    intPosition = intPosition + 1
    End If

    Last

    intPosition = datatable.Rows.Count-1
    If intPosition >= 0 Then
    DispData()
    Else
    intPosition = intPosition + 1
    End If

    private sub DispData()
    TextBoxName.Text = Datatable.Rows(intPosition)("FieldName")
    end sub

  • #4472
    Hi,

    Hope following code will be helpful.

    Sample Code Scenario:

    I am having two text boxes txtF1 and txtF2. DataSet ds is having only one datatable T1 with two columns F1 and F2. I am going to bind the txtF1 and txtF2 with T1.F1 and T1.F2 respectively and navigate using CurrencyManager.

    Note: Validations for BOF & EOF are omitted as we can easily do that using record count.



    txtF1.DataBindings.Add("Text",ds,"T1.F1");
    txtF2.DataBindings.Add("Text",ds,"T1.F2");

    <U> Next Button Click Event Code:</U>
    CurrencyManager cm =(CurrencyManager) this.BindingContext[ds,"T1"];
    cm.Position +=1;
    <U> Previous Button Click Event Code:</U>
    CurrencyManager cm =(CurrencyManager) this.BindingContext[ds,"T1"];
    cm.Position -=1;


    Cheers,
    Anbu.

  • #42016
    for movefirst, use the coding in button click event
    crow = 0
    showdata()

    for movenext,
    If crow < ds.Tables("Emp").Rows.Count - 1 Then
    crow = crow + 1
    End If
    showdata()

    for moveprevious,
    If crow > 0 Then
    crow = crow - 1
    End If
    showdata()

    for movelast,
    crow = ds.Tables("Emp").Rows.Count - 1
    showdata()

    crow must be an integer variable and
    ur showdata() should contain the following,

    txtid.Text = ds.Tables("Emp").Rows(crow)("Eid").ToString() (for all the textboxes)

    Hope this will help you.


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.