该如何回滚?
我是个初学者,以下是我的代码:
------翻页------
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
delete();
add();
lb1.Text = tibaoje();
float a1 = float.Parse(lb1.Text.Trim());
float b1 = float.Parse(lb2.Text.Trim());
if (a1 > b1)
{
Page.RegisterStartupScript("", "<script language='javascript'>window.alert('请重新填写!');</script>");
}
bind1();
}
}
private string tibaoje() //计算提报金额
{
string sqlstr5 = "select sum(amount*price) from material,tibaoxj where tibaoxj.wl_num=material.wl_num and tibaoxj.tb_num=@tb_num";
mycmd = new SqlCommand(sqlstr5, con);
con.Open();
mycmd.Parameters.Add("@tb_num", SqlDbType.Char).Value = (string)Session["tb_num"];
string tbcash = mycmd.ExecuteScalar().ToString();
con.Close();
return tbcash;
}
-------增加记录操作-------
private void add()
{
int n = GridView1.Rows.Count;
for (int i = 0; i < n; i++)
{
if (((TextBox)(GridView1.Rows[i].Cells[4].FindControl("tb1"))).Text != "")
{
key = GridView1.DataKeys[i].Value.ToString();
mycmd = new SqlCommand("insert into tibaoxj values(@tb_num,@wl_num,@amount)", con);
mycmd.Parameters.Add("@tb_num", SqlDbType.Char).Value = (string)Session["tb_num"];
mycmd.Parameters.Add("@wl_num", SqlDbType.Char).Value = key;
mycmd.Parameters.Add("@amount", SqlDbType.Int).Value = ((TextBox)(GridView1.Rows[i].Cells[4].FindControl("tb1"))).Text;
con.Open();
mycmd.ExecuteNonQuery();
con.Close();
}
}
}
--------删除记录操作-------
private void delete()
{
int n1 = GridView1.Rows.Count;
for (int i = 0; i < n1; i++)
{
key = GridView1.DataKeys[i].Value.ToString();
string sqlstr2 = "select * from tibaoxj where tb_num=@tb_num and wl_num=@wl_num";
myda = new SqlDataAdapter(sqlstr2, con);
DataSet myds1 = new DataSet();
myda.SelectCommand.Parameters.Add("@tb_num", SqlDbType.Char).Value = (string)Session["tb_num"];
myda.SelectCommand.Parameters.Add("@wl_num", SqlDbType.Char).Value = key;
myda.Fill(myds1, "tibao1");
int count1 = myds1.Tables["tibao1"].Rows.Count;
if (count1 != 0)
{
mycmd = new SqlCommand("delete tibaoxj where tb_num=@tb_num and wl_num=@wl_num", con);
mycmd.Parameters.Add("@tb_num", SqlDbType.Char).Value = (string)Session["tb_num"];
mycmd.Parameters.Add("@wl_num", SqlDbType.Char).Value = key;
con.Open();
mycmd.ExecuteNonQu