亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

以下代碼中的id=" + id是什么意思?看不明白!

以下代碼中的id=" + id是什么意思?看不明白!

忽然笑 2021-12-02 11:07:53
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();}}
查看完整描述

3 回答

?
元芳怎么了

TA貢獻1798條經驗 獲得超7個贊

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的那個字段或者叫列

查看完整回答
反對 回復 2021-12-06
?
胡說叔叔

TA貢獻1804條經驗 獲得超8個贊

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();
}
}



查看完整回答
反對 回復 2021-12-06
?
慕的地8271018

TA貢獻1796條經驗 獲得超4個贊

string id = "abc";
string sqlStr = "delete from xxx where id = " + id
此時
sqlStr = "delete .... where id = abc"
就是拼接字符串而已

查看完整回答
反對 回復 2021-12-06
  • 3 回答
  • 0 關注
  • 586 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號