Skip to content
Loading
  • 0
    Hiiii Jefferson S Motta,
     
    thank you for your reply... I have tried the same but I'm sorry it's not working.
    I have attached two screen shots with necessary comments on them. 
    Please check them.
     
    thanks once again...
     
    Mayank Jani
    0
  • Jefferson S. Motta
    0
    Ops,
     
    try this and let me know:
     
    1. using System;    
    2. using System.Collections.Generic;    
    3. using System.ComponentModel;    
    4. using System.Data;    
    5. using System.Drawing;    
    6. using System.Linq;    
    7. using System.Text;    
    8. using System.Windows.Forms;    
    9. using System.Data.OleDb;    
    10.     
    11. namespace RecordNavigation    
    12. {    
    13.     public partial class Form1 : Form    
    14.     {    
    15.         OleDbConnection MyConn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\SOFTWARES\Experiments\ExperimentsMAS.accdb");    
    16.     
    17.         public Form1()    
    18.         {    
    19.             InitializeComponent();    
    20.             // Prev button will be enabled after the btnNext_Click raises  
    21.             btnPrev.Enabled = false;    
    22.         }    
    23.     
    24.            
    25.         int n = -1; // moving index    
    26.     
    27.         private void btnPrev_Click(object sender, EventArgs e)    
    28.         {    
    29.             OleDbDataAdapter FetchPrev = new OleDbDataAdapter("Select * From FNPL Where PartyID='" + textBox1.Text + "' Order By PartySr DESC", MyConn);    
    30.     
    31.             DataSet dsFetchPrev = new DataSet();    
    32.             FetchPrev.Fill(dsFetchPrev);    
    33.      
    34.             if (dsFetchPrev.Tables[0].Rows.Count > 0  
    35.                && dsFetchPrev.Tables[0].Rows.Count >= n)  
    36.             {    
    37.                 n--;    
    38.     
    39. // you need use the Rows[n], was 0, so it was getting always the first row    
    40.                 textBox2.Text = (dsFetchPrev.Tables[0].Rows[n].ItemArray[2].ToString());    
    41.                 textBox3.Text = (dsFetchPrev.Tables[0].Rows[n].ItemArray[3].ToString());    
    42.                 textBox4.Text = (dsFetchPrev.Tables[0].Rows[n].ItemArray[4].ToString());    
    43.                 textBox5.Text = (dsFetchPrev.Tables[0].Rows[n].ItemArray[5].ToString());    
    44.             }    
    45.     
    46.             else    
    47.             {    
    48.                 MessageBox.Show("No More Record to Show.", "End of Record...");    
    49.                      
    50.             }    
    51.                 
    52.         }    
    53.     
    54.         private void btnNext_Click(object sender, EventArgs e)    
    55.         {    
    56.             OleDbDataAdapter FetchNext = new OleDbDataAdapter("Select * From FNPL Where PartyID='" + textBox1.Text + "' Order By PartySr", MyConn);    
    57.     
    58.             DataSet dsFetchNext = new DataSet();    
    59.             FetchNext.Fill(dsFetchNext);    
    60.     
    61.             if (dsFetchNext.Tables[0].Rows.Count >= 0  
    62.                && dsFetchNext.Tables[0].Rows.Count > n + 1) // 1 >  -1 + 1 = 0    
    63.             {    
    64.                 n++;    
    65.                 textBox2.Text = (dsFetchPrev.Tables[0].Rows[n].ItemArray[2].ToString());    
    66.                 textBox3.Text = (dsFetchPrev.Tables[0].Rows[n].ItemArray[3].ToString());    
    67.                 textBox4.Text = (dsFetchPrev.Tables[0].Rows[n].ItemArray[4].ToString());    
    68.                 textBox5.Text = (dsFetchPrev.Tables[0].Rows[n].ItemArray[5].ToString());    
    69.                 btnPrev.Enabled = true; // enable go prev    
    70.             }    
    71.             else    
    72.             {    
    73.                      
    74.                 MessageBox.Show("No More Record to Show.", "End of Record...");    
    75.                      
    76.             }    
    77.         }    
    78.     
    79.         private void Form1_Load(object sender, EventArgs e)    
    80.         {    
    81.                 
    82.         }    
    83.     }    
    84. }   
     
    0
  • 0
    Hiii,
    Sorry again, same result...
     
    as far as I understood, every time when I click 'Next', the click event for the button runs the query again and again and shows the first record.
     
    could you please let me know if I can use any loop for the dataset? because I think, the query and dataset should not be there in the click event of the button. only execution of the dataset should be there, or something like that.
     
    How about this... when click the 'Next' button, the query execute and dataset create only once then go to the loop until the records end... I do not know how to do that..
     
    Thanks
     
     Mayank Jani
    0