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

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

請問C#連接數據庫報錯,“=”附近有語法,該怎么解決?

請問C#連接數據庫報錯,“=”附近有語法,該怎么解決?

慕斯王 2021-12-02 11:07:39
DataSet ds;DataRow dr;string newsid;void Page_Load(Object sender, EventArgs e){SqlConnection MyConnection;string ConnStr, strCon;newsid = Request.Params["id"]; MyConnection = new SqlConnection("server=ADMIN-PC;database=news;uid=sa;pwd='123456'");MyConnection.Open();string strCom = "Select biaoti,zhaizi,neirong,img,counter,shijian from news where id=" + newsid;ds = new DataSet();SqlDataAdapter myCommand = new SqlDataAdapter(strCom, MyConnection);myCommand.Fill(ds, "news");dr = ds.Tables["news"].Rows[0];strCon = "Select counter from news where id=" + newsid;SqlCommand mycommand2 = new SqlCommand(strCon, MyConnection);SqlDataReader reader = mycommand2.ExecuteReader();reader.Read();int i = reader.GetInt32(0);i++;reader.Close(); strCon = "Update news set counter=" + i.ToString() + "where (id=" + newsid + ")";mycommand2.CommandText = strCon;mycommand2.ExecuteNonQuery(); MyConnection.Close(); }
查看完整描述

2 回答

?
阿波羅的戰車

TA貢獻1862條經驗 獲得超6個贊

這個肯定是SQL語句的錯誤
Select biaoti,zhaizi,neirong,img,counter,shijian from news where id=' "+ newsid+"'
Select counter from news where id=' "+ newsid+"'
Update news set counter=" + i.ToString() + "where (id=" + newsid + ")
前兩條錯了 在sql2005修改后之后通過

查看完整回答
反對 回復 2021-12-06
?
蝴蝶不菲

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

strCon = "Update news set counter=" + i.ToString() + "where (id=" + newsid + ")";
在where前加一個空格

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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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