Click here to Skip to main content
14,984,183 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to insert all the cell value of a grid view into a .mdb file.But the it can only able to insert only the page size of the gridview.if the page size of gridview is 20 then it can only able to insert 20 records only.How to insert all the rows of gridview.


C#
foreach (GridViewRow g1 in GVSalDet.Rows)
               {
                   string insertsql = string.Format("insert into RepTab ( EmpID, EmpName GName,DName,CName,Sal,Ptax) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}' )", g1.Cells[1].Text.ToString(), g1.Cells[2].Text.ToString(), g1.Cells[3].Text.ToString(), g1.Cells[4].Text.ToString(),
                              g1.Cells[5].Text.ToString(),float.Parse(g1.Cells[6].Text.ToString()),float.Parse(g1.Cells[7].Text.ToString()));

                   module.ReportNonQuery(insertsql);
               }



ReportNonQuery is class file
Posted

Before Looping set AllowPaging = false and rebind the GridView.
C#
GVSalDet.AllowPaging = false;
GVSalDet.DataBind();
You should change your code something like this
int count=0;int pagesize=20;
<pre lang="cs">foreach (GridViewRow g1 in GVSalDet.Rows)
               {
if(count <= pagesize){
                   string insertsql = string.Format("insert into RepTab ( EmpID, EmpName GName,DName,CName,Sal,Ptax) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}' )", g1.Cells[1].Text.ToString(), g1.Cells[2].Text.ToString(), g1.Cells[3].Text.ToString(), g1.Cells[4].Text.ToString(),
                              g1.Cells[5].Text.ToString(),float.Parse(g1.Cells[6].Text.ToString()),float.Parse(g1.Cells[7].Text.ToString()));

                   module.ReportNonQuery(insertsql);
          count +=1;
}               }
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900