本人为新手,在ASP.NET中尝试对GridView中的数据进行写入一个新表和更新原表时,只能更新和写入200多条后就提示超时了,请问有什么办法进行大批量的数据更新?下面是我自己写的,方法比较笨,麻烦给个简单的例子!!感谢
for (int i = 0; i < GridView1.Rows.Count; i++)
{
int 期末数 = Convert.ToInt32(GridView1.Rows[i].Cells[11].Text);
double 期末成本 = Convert.ToDouble(GridView1.Rows[i].Cells[12].Text);
string up = " update CW_JXC_stock set 期初数 ='" + 期末数 + "',月初成本 ='" + 期末成本 + "' where 货号=" + Convert.ToInt32(GridView1.Rows[i].Cells[0].Text);
SqlDataReader odc = DataBaseHelper.GetReader(up); string 货号 = GridView1.Rows[i].Cells[0].Text.ToString();
string 品名 = GridView1.Rows[i].Cells[1].Text.ToString();
string 规格 = GridView1.Rows[i].Cells[2].Text.ToString();
string 单位 = GridView1.Rows[i].Cells[3].Text.ToString();
string 类别 = GridView1.Rows[i].Cells[4].Text.ToString();
string 期初数 = GridView1.Rows[i].Cells[5].Text.ToString();
string 月初成本 = GridView1.Rows[i].Cells[6].Text.ToString();
string 入库数 = GridView1.Rows[i].Cells[7].Text.ToString();
string 进货成本 = GridView1.Rows[i].Cells[8].Text.ToString();
string 出库数 = GridView1.Rows[i].Cells[9].Text.ToString();
string 出库成本 = GridView1.Rows[i].Cells[10].Text.ToString();
string 月末数量 = GridView1.Rows[i].Cells[11].Text.ToString();
string 月末成本 = GridView1.Rows[i].Cells[12].Text.ToString();
string 加权价 = GridView1.Rows[i].Cells[13].Text.ToString();
string riqi = Convert.ToString(System.DateTime.Now.ToString("yyyy-MM")); string strSql = "insert into JXC_History_Month_Report(日期,货号,品名,规格,单位,类别,期初数,月初成本,入库数,进货成本,出库数,出库成本,期末数,期末成本,加权价) values('" + riqi + "','" + 货号 + "','" + 品名 + "','" + 规格 + "','" + 单位 + "','" + 类别 + "','" + 期初数 + "','" + 月初成本 + "','" + 入库数 + "','" + 进货成本 + "','" + 出库数 + "','" + 出库成本 + "','" + 月末数量 + "','" + 月末成本 + "','" + 加权价 + "')";
DataSet mydata = DataBaseHelper.GetDataSet(strSql);
string rukubiao = "TRUNCATE TABLE CW_JXC_ruku";
DataSet seta = DataBaseHelper.GetDataSet(rukubiao);
string chukubiao = "TRUNCATE TABLE CW_JXC_chuku";
DataSet setb = DataBaseHelper.GetDataSet(chukubiao); }
for (int i = 0; i < GridView1.Rows.Count; i++)
{
int 期末数 = Convert.ToInt32(GridView1.Rows[i].Cells[11].Text);
double 期末成本 = Convert.ToDouble(GridView1.Rows[i].Cells[12].Text);
string up = " update CW_JXC_stock set 期初数 ='" + 期末数 + "',月初成本 ='" + 期末成本 + "' where 货号=" + Convert.ToInt32(GridView1.Rows[i].Cells[0].Text);
SqlDataReader odc = DataBaseHelper.GetReader(up); string 货号 = GridView1.Rows[i].Cells[0].Text.ToString();
string 品名 = GridView1.Rows[i].Cells[1].Text.ToString();
string 规格 = GridView1.Rows[i].Cells[2].Text.ToString();
string 单位 = GridView1.Rows[i].Cells[3].Text.ToString();
string 类别 = GridView1.Rows[i].Cells[4].Text.ToString();
string 期初数 = GridView1.Rows[i].Cells[5].Text.ToString();
string 月初成本 = GridView1.Rows[i].Cells[6].Text.ToString();
string 入库数 = GridView1.Rows[i].Cells[7].Text.ToString();
string 进货成本 = GridView1.Rows[i].Cells[8].Text.ToString();
string 出库数 = GridView1.Rows[i].Cells[9].Text.ToString();
string 出库成本 = GridView1.Rows[i].Cells[10].Text.ToString();
string 月末数量 = GridView1.Rows[i].Cells[11].Text.ToString();
string 月末成本 = GridView1.Rows[i].Cells[12].Text.ToString();
string 加权价 = GridView1.Rows[i].Cells[13].Text.ToString();
string riqi = Convert.ToString(System.DateTime.Now.ToString("yyyy-MM")); string strSql = "insert into JXC_History_Month_Report(日期,货号,品名,规格,单位,类别,期初数,月初成本,入库数,进货成本,出库数,出库成本,期末数,期末成本,加权价) values('" + riqi + "','" + 货号 + "','" + 品名 + "','" + 规格 + "','" + 单位 + "','" + 类别 + "','" + 期初数 + "','" + 月初成本 + "','" + 入库数 + "','" + 进货成本 + "','" + 出库数 + "','" + 出库成本 + "','" + 月末数量 + "','" + 月末成本 + "','" + 加权价 + "')";
DataSet mydata = DataBaseHelper.GetDataSet(strSql);
string rukubiao = "TRUNCATE TABLE CW_JXC_ruku";
DataSet seta = DataBaseHelper.GetDataSet(rukubiao);
string chukubiao = "TRUNCATE TABLE CW_JXC_chuku";
DataSet setb = DataBaseHelper.GetDataSet(chukubiao); }
解决方案 »
- 如何实现VS工具栏拖动的效果
- 刚刚学习
- 急用!如何编写软件注册权文档?
- 关于Math.Round方法的问题
- 救救小弟了! C#通过Remoting调用串口 读硬件数据问题!
- 求助,小弟现在编程急需一本名为《C#高级程序员指南》,那位大虾知道请帮忙!谢
- TextBox小问题,难倒专家
- SqlDataAdapter使用的问题
- c#怎么播放mp3文件
- 在DataList的模板列中插入Img,其中src='<%# DataBinder.Eval(Container.DataItem, "title_id", "/quickstart/aspplus/images/title-{0}
- 封装文件格式与文件格式
- 文本框指定字体加粗问题
https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlbulkcopy(v=vs.110).aspx
照着做