批量删除无法删除,没有任何提示,但是数据还在.
sid的值看上去也是正常的
sid的值看上去也是正常的
1using System;
2using System.Data;
3using System.Data.OleDb;
4using System.Configuration;
5using System.Collections;
6using System.Web;
7using System.Web.Security;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.WebControls.WebParts;
11using System.Web.UI.HtmlControls;
12
13
14 public partial class ATitle : System.Web.UI.Page
15 {
16 protected void Page_Load(object sender, EventArgs e)
17 {
18 Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
19 if (!this.IsPostBack)
20 {
21 bt_selectAll.Text = "全部选中S";
22 string ToPage = Request.QueryString["ToPage"];
23 if (ToPage == null)
24 {
25 ToPage = "1";
26 }
27 /* if (!StrRegExp.IsID(ToPage)) //StrRegExp.IsID是原来代码里用来检查ToPage是否为规定的3位0-9的数字
28 {
29 ToPage = "1";
30 }
31 */
32
33 string type = Request.QueryString["type"];
34 if (type == null)
35 {
36 type = "1";
37 }
38 this.Bind_rptList(Convert.ToInt32(ToPage), Convert.ToInt32(type));
39
40 }
41
42
43 }
44 private void Bind_rptList(int ToPage,int type)
45 {
46 int CurrentPage = ToPage;
47 int PageSize = 20;
48 int PageCount;
49 int RecordCount;
50 string PageSQL;
51 string DataTable = "guestbook";
52 string DataFiled = "g_ID";
53 //string DataFileds = "ID,UserName,Face,Sex,Ip,QQ,HomePage,Email,IsHidden,AddTime,Content,IsReplyed,ReplyTime,ReplyContent ";
54 string DataOrders = "g_ID Desc";
55 string DataCondition_where = "";
56 string DataCondition_and = "";
57
58 OleDbConnection objConn = db.CreateConnection();
59 objConn.Open();
60
61 if (type == 1)
62 {
63 DataCondition_where = " where g_IsReplyed = false ";
64 DataCondition_and = " and g_IsReplyed = false ";
65 }
66 //* 取得记录总数,计算总页数
67 string countSql = "select count(" + DataFiled + ") from " + DataTable + DataCondition_where;
68 OleDbCommand cmd = new OleDbCommand(countSql, objConn);
69 RecordCount = Convert.ToInt32(cmd.ExecuteScalar());//执行查询,并返回查询所返回的结果集中第一行的第一列。所有其他的列和行将被忽略。
70 if ((RecordCount % PageSize) != 0)
71 {
72 PageCount = RecordCount / PageSize + 1;
73 }
74 else
75 {
76 PageCount = RecordCount / PageSize;
77 }
78 if (ToPage > PageCount)
79 {
80 CurrentPage = PageCount;
81 }
82 if (CurrentPage <= 1)
83 {
84 PageSQL = "Select Top " + PageSize + " * From " + DataTable + " " + DataCondition_where + " Order By " + DataOrders;
85 }
86 else
87 {
88 PageSQL = "Select Top " + PageSize + " * From " + DataTable + " Where " + DataFiled + " Not In ( Select Top " + PageSize * (CurrentPage - 1) + " " + DataFiled + " From " + DataTable + " " + DataCondition_where + " Order By " + DataOrders + " ) " + DataCondition_and + " Order By " + DataOrders;
89
90 }
91 OleDbDataAdapter oda = new OleDbDataAdapter(PageSQL, objConn);
92 DataSet ds = new DataSet();
93 oda.Fill(ds, "infList");
94 this.lbTotalPage.Text = Convert.ToString(PageCount);
95 this.hlkFirstPage.NavigateUrl = "?type=" + type + "&ToPage=1";
96 this.hlkLastPage.NavigateUrl = "?type=" + type + "&ToPage=" + PageCount;
97 this.lbCurrentPage.Text = Convert.ToString(CurrentPage);
98 if (CurrentPage <= 1)
99 {
100 this.hlkPrevPage.Enabled = false;
101 CurrentPage = 1;
102 }
103 else
104 {
105 this.hlkPrevPage.Enabled = true;
106 this.hlkPrevPage.NavigateUrl = "?type=" + type + "&ToPage=" + (ToPage - 1);
107 }
108 if (CurrentPage >= PageCount)
109 {
110 this.hlkNextPage.Enabled = false;
111 CurrentPage = PageCount;
112 }
113 else
114 {
115 this.hlkNextPage.Enabled = true;
116 this.hlkNextPage.NavigateUrl = "?type=" + type + "&ToPage=" + (ToPage + 1);
117 }
118 rptList.DataSource = ds.Tables["infList"].DefaultView;
119 rptList.DataBind();
120 objConn.Close();
121 }
122 protected void bt_show_Click(object sender, EventArgs e)
123 {
124 string sID="";
125 foreach (RepeaterItem item in rptList.Items)
126 {
127 CheckBox chkbox1 = (CheckBox)item.FindControl("ckBox_single");
128
129 if (chkbox1.Checked == true)
130 {
131 sID += ((HtmlInputHidden)item.FindControl("SelectedID")).Value + ',';
132 }
133 }
134 sID = sID.Trim(',');
135 Label1.Text = sID;
136 OleDbConnection objConn = db.CreateConnection();
137 string strSql = "delete from guestbook where (g_id in (@id))";
138 OleDbCommand cmd = new OleDbCommand(strSql, objConn);
139 cmd.Parameters.AddWithValue("@id", sID);
140 objConn.Open();
141 cmd.ExecuteNonQuery();
142 objConn.Close();
143 Response.Write("<script>alert('删除成功,跳转到首页');history.back();</script>");
144 }
145
146}
2using System.Data;
3using System.Data.OleDb;
4using System.Configuration;
5using System.Collections;
6using System.Web;
7using System.Web.Security;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.WebControls.WebParts;
11using System.Web.UI.HtmlControls;
12
13
14 public partial class ATitle : System.Web.UI.Page
15 {
16 protected void Page_Load(object sender, EventArgs e)
17 {
18 Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
19 if (!this.IsPostBack)
20 {
21 bt_selectAll.Text = "全部选中S";
22 string ToPage = Request.QueryString["ToPage"];
23 if (ToPage == null)
24 {
25 ToPage = "1";
26 }
27 /* if (!StrRegExp.IsID(ToPage)) //StrRegExp.IsID是原来代码里用来检查ToPage是否为规定的3位0-9的数字
28 {
29 ToPage = "1";
30 }
31 */
32
33 string type = Request.QueryString["type"];
34 if (type == null)
35 {
36 type = "1";
37 }
38 this.Bind_rptList(Convert.ToInt32(ToPage), Convert.ToInt32(type));
39
40 }
41
42
43 }
44 private void Bind_rptList(int ToPage,int type)
45 {
46 int CurrentPage = ToPage;
47 int PageSize = 20;
48 int PageCount;
49 int RecordCount;
50 string PageSQL;
51 string DataTable = "guestbook";
52 string DataFiled = "g_ID";
53 //string DataFileds = "ID,UserName,Face,Sex,Ip,QQ,HomePage,Email,IsHidden,AddTime,Content,IsReplyed,ReplyTime,ReplyContent ";
54 string DataOrders = "g_ID Desc";
55 string DataCondition_where = "";
56 string DataCondition_and = "";
57
58 OleDbConnection objConn = db.CreateConnection();
59 objConn.Open();
60
61 if (type == 1)
62 {
63 DataCondition_where = " where g_IsReplyed = false ";
64 DataCondition_and = " and g_IsReplyed = false ";
65 }
66 //* 取得记录总数,计算总页数
67 string countSql = "select count(" + DataFiled + ") from " + DataTable + DataCondition_where;
68 OleDbCommand cmd = new OleDbCommand(countSql, objConn);
69 RecordCount = Convert.ToInt32(cmd.ExecuteScalar());//执行查询,并返回查询所返回的结果集中第一行的第一列。所有其他的列和行将被忽略。
70 if ((RecordCount % PageSize) != 0)
71 {
72 PageCount = RecordCount / PageSize + 1;
73 }
74 else
75 {
76 PageCount = RecordCount / PageSize;
77 }
78 if (ToPage > PageCount)
79 {
80 CurrentPage = PageCount;
81 }
82 if (CurrentPage <= 1)
83 {
84 PageSQL = "Select Top " + PageSize + " * From " + DataTable + " " + DataCondition_where + " Order By " + DataOrders;
85 }
86 else
87 {
88 PageSQL = "Select Top " + PageSize + " * From " + DataTable + " Where " + DataFiled + " Not In ( Select Top " + PageSize * (CurrentPage - 1) + " " + DataFiled + " From " + DataTable + " " + DataCondition_where + " Order By " + DataOrders + " ) " + DataCondition_and + " Order By " + DataOrders;
89
90 }
91 OleDbDataAdapter oda = new OleDbDataAdapter(PageSQL, objConn);
92 DataSet ds = new DataSet();
93 oda.Fill(ds, "infList");
94 this.lbTotalPage.Text = Convert.ToString(PageCount);
95 this.hlkFirstPage.NavigateUrl = "?type=" + type + "&ToPage=1";
96 this.hlkLastPage.NavigateUrl = "?type=" + type + "&ToPage=" + PageCount;
97 this.lbCurrentPage.Text = Convert.ToString(CurrentPage);
98 if (CurrentPage <= 1)
99 {
100 this.hlkPrevPage.Enabled = false;
101 CurrentPage = 1;
102 }
103 else
104 {
105 this.hlkPrevPage.Enabled = true;
106 this.hlkPrevPage.NavigateUrl = "?type=" + type + "&ToPage=" + (ToPage - 1);
107 }
108 if (CurrentPage >= PageCount)
109 {
110 this.hlkNextPage.Enabled = false;
111 CurrentPage = PageCount;
112 }
113 else
114 {
115 this.hlkNextPage.Enabled = true;
116 this.hlkNextPage.NavigateUrl = "?type=" + type + "&ToPage=" + (ToPage + 1);
117 }
118 rptList.DataSource = ds.Tables["infList"].DefaultView;
119 rptList.DataBind();
120 objConn.Close();
121 }
122 protected void bt_show_Click(object sender, EventArgs e)
123 {
124 string sID="";
125 foreach (RepeaterItem item in rptList.Items)
126 {
127 CheckBox chkbox1 = (CheckBox)item.FindControl("ckBox_single");
128
129 if (chkbox1.Checked == true)
130 {
131 sID += ((HtmlInputHidden)item.FindControl("SelectedID")).Value + ',';
132 }
133 }
134 sID = sID.Trim(',');
135 Label1.Text = sID;
136 OleDbConnection objConn = db.CreateConnection();
137 string strSql = "delete from guestbook where (g_id in (@id))";
138 OleDbCommand cmd = new OleDbCommand(strSql, objConn);
139 cmd.Parameters.AddWithValue("@id", sID);
140 objConn.Open();
141 cmd.ExecuteNonQuery();
142 objConn.Close();
143 Response.Write("<script>alert('删除成功,跳转到首页');history.back();</script>");
144 }
145
146}