为什么数据库中更新不了!
string mytitle = title.Text;
string mycontent = content.Value;
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + Server.MapPath( "..//bbs//netdatamdb//netrencaiwang.mdb ");
OleDbConnection myconn = new OleDbConnection(ConnectionString);
myconn.Open();
string cmdText = @ "update peixun set ptitle= ' "+mytitle+ " ',pcontent= ' "+mycontent+
@ " ' where id= "+Session[ "newsid "];
OleDbCommand mycommand = new OleDbCommand();
mycommand.Connection = myconn;
mycommand.CommandText = cmdText;
mycommand.ExecuteNonQuery();
myconn.Close();
Response.Write( " <script> alert( '更新成功! ') </script> ");
------解决方案--------------------------------------------------------
调试到string cmdText = @ "update peixun set ptitle= ' "+mytitle+ " ',pcontent= ' "+mycontent+ @ " ' where id= "+Session[ "newsid "];
看看cmdText是什么内容。会不会是Session[ "newsid "]没内容?
------解决方案--------------------------------------------------------
调试到string cmdText = @ "update peixun set ptitle= ' "+mytitle+ " ',pcontent= ' "+mycontent+ @ " ' where id= "+Session[ "newsid "];
看看cmdText是什么内容。会不会是Session[ "newsid "]没内容?
------解决方案--------------------------------------------------------
程序错了,怎么每一句后面有分号啊,
------解决方案--------------------------------------------------------
string cmdText = "update peixun set ptitle= ' " + mytitle + " ',pcontent= ' " + mycontent + " ' where id = " + Session[ "newsid "].ToString();
------解决方案--------------------------------------------------------
如果你的id是字符类型的,那就像amandag(高歌)说的那样,判断id的时候用Session[ "newid "].ToString();
Session[ "newid "]是object类型,要转成string类型才能比较!
------解决方案--------------------------------------------------------
如果数据库里 id是整数类型
string cmdText = "update peixun set ptitle= ' " + mytitle + " ',pcontent= ' " + mycontent + " ' where id = " + Convert.ToInt32(Session[ "newsid "]);
如果数据库里 id是字符类型
string cmdText = "update peixun set ptitle= ' " + mytitle + " ',pcontent= ' " + mycontent + " ' where id = ' " + Convert.ToString(Session[ "newsid "]) + " ' ";
------解决方案--------------------------------------------------------
用断点跟踪看cmdText的数据是否正确..
------解决方案--------------------------------------------------------