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();
}
}

New Topic/Question
This topic is locked


MultiQuote








|