在線等,,以下多選刪除報錯,

shixianyong shixianyong 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
將 varchar 數值 'GridView1.DataKeys[gvr.DataItemIndex].Value' 轉換成資料型別為 int 的資料行語法錯誤。

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string connStr = ConfigurationManager.ConnectionStrings["BTS"].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
DataSet ds = new DataSet();
SqlCommand comm = new SqlCommand();
SqlDataAdapter sqlad = new SqlDataAdapter();
comm.Connection = conn;
comm.CommandText = "select * from bts";
sqlad.SelectCommand = comm;
//Response.Write(sqlad.SelectCommand.CommandText);
sqlad.Fill(ds, "bts");
GridView1.DataSource = ds.Tables["bts"];
GridView1.DataBind();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
if (ch.Checked)
{
//Ret2.Text += "<li>GridView1 您选择的是(键值):" + GridView1.DataKeys[gvr.DataItemIndex].Value.ToString();
string connStr = ConfigurationManager.ConnectionStrings["BTS"].ConnectionString;
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
DataSet ds = new DataSet();
SqlCommand comm = new SqlCommand();
SqlDataAdapter sqlad = new SqlDataAdapter();
string sql;
sql = "delete from bts where au_id= 'GridView1.DataKeys[gvr.DataItemIndex].Value'";
comm.Connection = conn;
comm.CommandText = sql;
comm.ExecuteNonQuery();

}
}
}

protected void CheckAll(object sender, EventArgs e)
{
CheckBox cbx = (CheckBox)sender;
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
ch.Checked = cbx.Checked;
}
}
...全文

相关推荐

评论 14
收藏 已收藏
分享
返回顶部
shixianyong
.NET社区 62,271 成员 668,968 内容