hosseines
پنج شنبه 10 تیر 1395, 00:01 صبح
سلام خدمت دوستان
من تقریبا 50 تا رکورد در بانک اطلاعاتی دارم که میخواهم اطلاعات را بصورت صفحه بندی در دیتاگرید نمایش دهم هر صفحه 10 رکورد ولی بازدن دکمه صفحه بعدی خطا میده.
private OleDbCommand cmd1;
private OleDbCommand cmd2;
private OleDbDataAdapter ada1;
DataSet ds;
static OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DB.mdb;Persist Security Info=True");
//--------------------------------------
private int pageSize = 10;
private int currentpageindex = 0;
private int Totalpage = 0;
private void Form1_Load(object sender, EventArgs e)
{
cmd1 = new OleDbCommand("select * from Tbl_Personel order by CodePersenol", con);
ds = new DataSet();
ada1 = new OleDbDataAdapter(cmd1);
ada1.Fill(ds, "Tbl_Personel");
DWG1.DataSource = ds;
DWG1.DataMember = "Tbl_Personel";
this.calculateTotalpages();
this.DWG1.ReadOnly = true;
this.DWG1.DataSource = Getcurrentrecords(1, con);
txtNumRecord.Text = (currentpageindex + 1) + " از " + Totalpage;
}
public void calculateTotalpages()
{
int rowCount = ds.Tables["Tbl_Personel"].Rows.Count;
this.Totalpage = rowCount / pageSize;
if (rowCount % pageSize > 0)
{
this.Totalpage += 1;
}
}
private DataTable Getcurrentrecords(int page, OleDbConnection con)
{
DataTable dt = new DataTable();
if (page == 1)
{
cmd2 = new OleDbCommand(" select Top " + pageSize + " * from Tbl_Personel order by CodePersenol", con);
//InitializePageNavigationButtons();
}
else
{
int previouspagelimit = (page - 1) * pageSize;
cmd2 = new OleDbCommand(" select Top " + pageSize + " * from Tbl_Personel " + " CodePersenol not in " +
"(select Top " + previouspagelimit + " CodePersenol from Tbl_Personel order by CodePersenol)", con);
}
try
{
this.ada1.SelectCommand = cmd2;
this.ada1.Fill(dt);
}
finally
{
con.Close();
}
return dt;
}
private void btnNext_Click(object sender, EventArgs e)
{
if (this.currentpageindex < this.Totalpage)
{
this.currentpageindex++;
this.DWG1.DataSource = Getcurrentrecords(this.currentpageindex, con);
txtNumRecord.Text = currentpageindex + " از " + Totalpage;
}
}
private void btnend_Click(object sender, EventArgs e)
{
this.currentpageindex = this.Totalpage;
txtNumRecord.Text = currentpageindex + " از " + Totalpage;
this.DWG1.DataSource = Getcurrentrecords(this.currentpageindex, con);
}
private void btnback_Click(object sender, EventArgs e)
{
if (this.currentpageindex > 1)
{
this.currentpageindex--;
this.DWG1.DataSource = Getcurrentrecords(this.currentpageindex, con);
txtNumRecord.Text = currentpageindex + " از " + Totalpage;
}
}
private void btnHome_Click(object sender, EventArgs e)
{
this.currentpageindex = 1;
this.DWG1.DataSource = Getcurrentrecords(this.currentpageindex, con);
txtNumRecord.Text = currentpageindex + " از " + Totalpage;
}
کجا اشتباه کردم...؟
من تقریبا 50 تا رکورد در بانک اطلاعاتی دارم که میخواهم اطلاعات را بصورت صفحه بندی در دیتاگرید نمایش دهم هر صفحه 10 رکورد ولی بازدن دکمه صفحه بعدی خطا میده.
private OleDbCommand cmd1;
private OleDbCommand cmd2;
private OleDbDataAdapter ada1;
DataSet ds;
static OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=DB.mdb;Persist Security Info=True");
//--------------------------------------
private int pageSize = 10;
private int currentpageindex = 0;
private int Totalpage = 0;
private void Form1_Load(object sender, EventArgs e)
{
cmd1 = new OleDbCommand("select * from Tbl_Personel order by CodePersenol", con);
ds = new DataSet();
ada1 = new OleDbDataAdapter(cmd1);
ada1.Fill(ds, "Tbl_Personel");
DWG1.DataSource = ds;
DWG1.DataMember = "Tbl_Personel";
this.calculateTotalpages();
this.DWG1.ReadOnly = true;
this.DWG1.DataSource = Getcurrentrecords(1, con);
txtNumRecord.Text = (currentpageindex + 1) + " از " + Totalpage;
}
public void calculateTotalpages()
{
int rowCount = ds.Tables["Tbl_Personel"].Rows.Count;
this.Totalpage = rowCount / pageSize;
if (rowCount % pageSize > 0)
{
this.Totalpage += 1;
}
}
private DataTable Getcurrentrecords(int page, OleDbConnection con)
{
DataTable dt = new DataTable();
if (page == 1)
{
cmd2 = new OleDbCommand(" select Top " + pageSize + " * from Tbl_Personel order by CodePersenol", con);
//InitializePageNavigationButtons();
}
else
{
int previouspagelimit = (page - 1) * pageSize;
cmd2 = new OleDbCommand(" select Top " + pageSize + " * from Tbl_Personel " + " CodePersenol not in " +
"(select Top " + previouspagelimit + " CodePersenol from Tbl_Personel order by CodePersenol)", con);
}
try
{
this.ada1.SelectCommand = cmd2;
this.ada1.Fill(dt);
}
finally
{
con.Close();
}
return dt;
}
private void btnNext_Click(object sender, EventArgs e)
{
if (this.currentpageindex < this.Totalpage)
{
this.currentpageindex++;
this.DWG1.DataSource = Getcurrentrecords(this.currentpageindex, con);
txtNumRecord.Text = currentpageindex + " از " + Totalpage;
}
}
private void btnend_Click(object sender, EventArgs e)
{
this.currentpageindex = this.Totalpage;
txtNumRecord.Text = currentpageindex + " از " + Totalpage;
this.DWG1.DataSource = Getcurrentrecords(this.currentpageindex, con);
}
private void btnback_Click(object sender, EventArgs e)
{
if (this.currentpageindex > 1)
{
this.currentpageindex--;
this.DWG1.DataSource = Getcurrentrecords(this.currentpageindex, con);
txtNumRecord.Text = currentpageindex + " از " + Totalpage;
}
}
private void btnHome_Click(object sender, EventArgs e)
{
this.currentpageindex = 1;
this.DWG1.DataSource = Getcurrentrecords(this.currentpageindex, con);
txtNumRecord.Text = currentpageindex + " از " + Totalpage;
}
کجا اشتباه کردم...؟