gridview 批量保存到SQL表中,点保存只保存当前页,再点保存就会把所有页都写到后台
protected void btnsave_Click(object sender, EventArgs e)
{
gvRecord.AllowPaging = false;
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
SqlTransaction tran = null;
try
{
conn.Open();
for (int i = 0; i < gvRecord.Rows.Count; i++)
{
//sda.SelectCommand.Transaction = sqlT;
string sqlStr = "";
SqlCommand comm = new SqlCommand();
tran = conn.BeginTransaction();
string strA = gvRecord.Rows[i].Cells[0].Text.Trim().ToString();
string strB = gvRecord.Rows[i].Cells[1].Text.Trim().ToString();
string strC = gvRecord.Rows[i].Cells[2].Text.Trim().ToString();
sqlStr += "INSERT INTO dbo.tb_mm (A, B, C,) VALUES (‘“+A+”’,‘“+B+”’,‘“+C+”’,);";
comm.CommandText = sqlStr;
comm.Connection = conn;
comm.Transaction = tran;
comm.ExecuteNonQuery();
tran.Commit();
}
}
catch (Exception ex)
{
Response.Write("更新失败,失败原因:" + ex.Message);
tran.Rollback(); //事务回滚
}
finally
{
conn.Close();
}
}
{
gvRecord.AllowPaging = false;
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);
SqlTransaction tran = null;
try
{
conn.Open();
for (int i = 0; i < gvRecord.Rows.Count; i++)
{
//sda.SelectCommand.Transaction = sqlT;
string sqlStr = "";
SqlCommand comm = new SqlCommand();
tran = conn.BeginTransaction();
string strA = gvRecord.Rows[i].Cells[0].Text.Trim().ToString();
string strB = gvRecord.Rows[i].Cells[1].Text.Trim().ToString();
string strC = gvRecord.Rows[i].Cells[2].Text.Trim().ToString();
sqlStr += "INSERT INTO dbo.tb_mm (A, B, C,) VALUES (‘“+A+”’,‘“+B+”’,‘“+C+”’,);";
comm.CommandText = sqlStr;
comm.Connection = conn;
comm.Transaction = tran;
comm.ExecuteNonQuery();
tran.Commit();
}
}
catch (Exception ex)
{
Response.Write("更新失败,失败原因:" + ex.Message);
tran.Rollback(); //事务回滚
}
finally
{
conn.Close();
}
}
...全文
相关推荐
asp.net下gridview 批量删除的实现方法第1/3页
要实现的效果很简单,看下图片:功能:选中CheckBox,后从数据库中删除选中项。文章侧重将如何实现批量删除,对于如何链接数据库和绑定数据不做详细解释。1 我们先要在GridView中添加一列为CheckBox。代码如下: 代码如下:<asp GridView ID=”GridView1″ runat u201dserver” AutoGenerateColumns=”false”> <Columns> <asp BoundField DataField=”vote_id” HeaderText> <asp:BoundField DataFi
Gridview数据真分页
Gridview数据真分页,包含存储过程、前台绑定、后台操作说明
GridView全选与批量删除
GridView全选与批量删除所使用到的技术: Asp.net技术及数据源控件GridView且使用到Linq技术
通过在GridView中CheckBox多选的批量删除,经典
通过在GridView中CheckBox多选的批量删除,绝对经典哦哦
gridview添加复选框批量操作代码
使用gridview技术可以实现复选框的批量操作


