3 Replies - 1100 Views - Last Post: 13 February 2013 - 08:24 AM

#1 Leader2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 05-February 13

Why still stucking for the Button "Last"?

Posted 13 February 2013 - 03:02 AM

Hi!

I have a form with two textboxs (txtBx_Name and txtBx_Datebirth) and fours button ("First, Previous, Next and Last").
But curiosly my problem it's on Button "Last". When I'm scrolling my record using all these buttons its works fine. Except the button "Last". When click this button there s message that says" There is no row at position -1.
Need explanation and help.
namespace dataBase1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        System.Data.SqlServerCe.SqlCeConnection con;
        System.Data.SqlServerCe.SqlCeDataAdapter da;
        DataSet ds1;

        int MaxRows = 0;
        int inc = 0;


        private void Form1_Load(object sender, EventArgs e)
        {
            con = new System.Data.SqlServerCe.SqlCeConnection();
            //con.Open();

            ds1 = new DataSet();

            con.ConnectionString = "Data Source=C:\\employees.sdf";
            string sql = "SELECT * From tbl_employees";
            da = new System.Data.SqlServerCe.SqlCeDataAdapter(sql,con);

            da.Fill(ds1, "Israel");
            NavigateRecords();

            //MessageBox.Show("Connection Open");

            //con.Close();

        }

        private void NavigateRecords()
        {
            
            DataRow dRow = ds1.Tables["Israel"].Rows[inc];
            textBox1.Text = dRow.ItemArray.GetValue(1).ToString();
            textBox2.Text = dRow.ItemArray.GetValue(2).ToString();
            textBox3.Text = dRow.ItemArray.GetValue(3).ToString();
            textBox4.Text = dRow.ItemArray.GetValue(4).ToString();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            if (inc != MaxRows - 1)
            {
                inc++;
                NavigateRecords();
            }
            else
            {
                MessageBox.Show("No more rows");
            }
        }

        private void btnPrevious_Click(object sender, EventArgs e)
        {
            if (inc > 0)
            {
                inc--;
                NavigateRecords();
            }
            else
            {
                MessageBox.Show("First Record");
            }
        }

        private void btnLast_Click(object sender, EventArgs e)
        {
            if (inc != MaxRows - 1)
            {
                inc = MaxRows - 1;
                NavigateRecords();
            }
        }

        private void btnFirst_Click(object sender, EventArgs e)
        {
            if (inc != 0)
            {
                inc = 0;
                NavigateRecords();
            }
        }


Is This A Good Question/Topic? 0
  • +

Replies To: Why still stucking for the Button "Last"?

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3662
  • View blog
  • Posts: 11,466
  • Joined: 05-May 12

Re: Why still stucking for the Button "Last"?

Posted 13 February 2013 - 06:41 AM

Probably should close this as a duplicate of the other post: http://www.dreaminco...he-button-last/
Was This Post Helpful? 0
  • +
  • -

#3 TheKirk  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 58
  • Joined: 10-February 13

Re: Why still stucking for the Button "Last"?

Posted 13 February 2013 - 06:55 AM

View PostSkydiver, on 13 February 2013 - 06:41 AM, said:

Probably should close this as a duplicate of the other post: http://www.dreaminco...he-button-last/


Report has been done.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9573
  • View blog
  • Posts: 36,255
  • Joined: 12-June 08

Re: Why still stucking for the Button "Last"?

Posted 13 February 2013 - 08:24 AM

Please do not open duplicate posts..

Closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1