第1个回答 2019-08-10
using
system.data.sqlclient;//引用命名空间
在方法中写
sqlconnection
conn=new
sqlconnection("persist
security
info=false;data
source=127.0.0.1;initial
catalog=databasename;user
id=userid;password=pwd");//连数据库
conn.open();//打开链接
sqlcommand
cmd=new
sqlcommand("delete
from
table1
where
qqq='qqq'",conn);//要执行的语句
int
x=cmd.executenonquery();//返回影响行数
if(x>0)
{
response.write("删除成功!");
}//如果大于0操作成功,小于等于0符合没有条件的行
cmd.dispose();释放资源
conn.close();//关闭连接
第2个回答 2008-11-08
首先,
你应该为Gridview增加一个模板列。然后模板设计里放个CheckBox。在删除按钮(这个删除按钮非Gridview自带的删除按钮)事件里遍历<for循环实现>CheckBox(用FindControl方法)。
如果该行被选中,则删除数据库中的记录。
第3个回答 2008-11-10
sqlcon = new SqlConnection(strCon);
SqlCommand sqlcom;
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbox.Checked == true)
{
string sqlstr = "delete from 飞狐工作室 where 身份证号码='" + GridView1.DataKeys[i].Value + "'";
sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
}
}
bind();
}
有不懂的问我
第4个回答 2008-11-08
RowDeleting(object sender, GridViewDeleteEventArgs e)事件里
写上处理句子.
delete from table where id=" + dataGridView1.DataKeys[e.RowIndex].Value.ToString().Trim()
this.dataGridView.DataKeys记得绑定数据ID在属性里有.