string SqlStr = "delete from PersonInfo where id=" + id;这里的id=" + id是什么意思?看不明白。

privatevoidcmdDelete(GridViewg1,GridViewDeleteEventArgse){stringid=g1.DataKeys[e.RowI... private void cmdDelete(GridView g1,GridViewDeleteEventArgs e)
{
string id = g1.DataKeys[e.RowIndex].Value.ToString();
string SqlStr = "delete from PersonInfo where id=" + id;

using (SqlConnection conn = new SqlConnection(ConnStr))
{
SqlCommand cmd = new SqlCommand(SqlStr, conn);
try
{
conn.Open();
int iValue = cmd.ExecuteNonQuery();
if (iValue > 0)
{
cmd.CommandText = "Select * from PersonInfo";
SqlDataReader dr = cmd.ExecuteReader();
this.GridView1.Caption = "人员信息表";
this.GridView1.DataSource = dr;
this.GridView1.DataBind();
}
}
展开
 我来答
迈讯科智能技术
2011-04-30 · TA获得超过266个赞
知道小有建树答主
回答量:305
采纳率:0%
帮助的人:177万
展开全部
string sqlStr = "delete from PersonInfo where id=" + id;
中的外面的id是引号里面id的参数,也就是说假设id=3,那么此时string sqlStr=“delete from PersonInfo where id=3”,那么在执行这条语句的时候就会将表PersonInfo表中id为3的那条记录删掉。外面的id是变量,要传入sql语句中的值,引号里面的id是PersonInfo表中名字为id的那个字段或者叫列
追问
string sqlStr = "delete from xxx where id = " + id
我直接写所string sqlStr = "delete from xxx where id = id"有没有区别?一样的吗?
追答
有区别,如果直接写入引号内id就不是参数了,你通过string id = g1.DataKeys[e.RowIndex].Value.ToString();获取来的id值就没有办法传递进sql语句中
百度网友c5ad3af7d
2011-04-30
知道答主
回答量:27
采纳率:0%
帮助的人:21.4万
展开全部
string id = g1.DataKeys[e.RowIndex].Value.ToString(); //获取 GridView DataKeys 属性的值(当前选中的)
string SqlStr = "delete from PersonInfo where id=" + id; // sql 语句 字符串拼接(就是删除语句, 你可以打个断点停住 看看是什么 你就知道了);

using (SqlConnection conn = new SqlConnection(ConnStr))
{// 以下是查询了, 把修改后的数据 从新从数据库里读出来 在显示
SqlCommand cmd = new SqlCommand(SqlStr, conn);
try
{
conn.Open();
int iValue = cmd.ExecuteNonQuery();
if (iValue > 0)
{
cmd.CommandText = "Select * from PersonInfo";
SqlDataReader dr = cmd.ExecuteReader();
this.GridView1.Caption = "人员信息表";
this.GridView1.DataSource = dr;
this.GridView1.DataBind();
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友6eed2f8
2011-04-30 · TA获得超过5082个赞
知道大有可为答主
回答量:3423
采纳率:0%
帮助的人:3886万
展开全部
string id = "abc";
string sqlStr = "delete from xxx where id = " + id
此时
sqlStr = "delete .... where id = abc"

就是拼接字符串而已
追问
string sqlStr = "delete from xxx where id = " + id
我直接写所string sqlStr = "delete from xxx where id = id"有没有区别?一样的吗?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式