带参数的UPDATE语句无法更新数据库问题
郁闷的快跳楼的,高手帮忙吧,分数不是问题,先行言谢了。stringcontent=Request.Form["content1"].ToString();//用来接收文本...
郁闷的快跳楼的,高手帮忙吧,分数不是问题,先行言谢了。
string content = Request.Form["content1"].ToString();//用来接收文本编辑器提交的文本(包括其格式)
string b = Request.Form["txtUserName"].ToString();//用来接收提交过来的编号
string dbpath2 = System.Configuration.ConfigurationSettings.AppSettings["dbpath"];
OleDbConnection conn2 = new OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;Data source=" + Server.MapPath(dbpath2));
conn2.Open();
string str = "update xianlu set richengshisu = @neirong where bianhao = @biaoti";
Response.Write(str);
OleDbCommand cmd1 = new OleDbCommand();
OleDbParameter biaoti = new OleDbParameter("@biaoti", OleDbType.VarChar);
biaoti.Value = b;
OleDbParameter neirong = new OleDbParameter("@neirong", OleDbType.VarChar);
neirong.Value = content;
cmd1.CommandText = str;
cmd1.Connection = conn2;
cmd1.Parameters.Add(biaoti);
cmd1.Parameters.Add(neirong);
try
{
cmd1.ExecuteNonQuery();
Response.Write("<br>"+str);
Response.Write("<script>alert('添加成功!');</script>");
Response.Write("<script>location.replace('../xianlu.aspx');</script>");
}
catch (OleDbException ex)
{
Response.Write("添加失败!"+ex.Message);
}
conn2.Close();
cmd1.Connection.Close();
cmd1.Dispose();
我用的是ACCESS数据库,richengshisu在数据库中的数据类型为备注,bianhao在数据库中的数据类型为文本。
Response.Write(str);的输出为:
update xianlu set richengshisu = @neirong where bianhao = @biaoti
Response.Write("<br>"+str);的输出为:
update xianlu set richengshisu = @neirong where bianhao = @biaoti
我也不知道应咋办了,伤心死了。弄了一晚上。有意者百度HI吧。伤心!绝望!……
---------谁来给我希望
有意者百度HI我吧.凌晨2点前在线.
俺并不是非要用这种方法,用其它方法也行,只要能实现这个要求.
1 当我在文本编辑器中,输入正确的编号和内容时,总是提示"添加成功",可到数据库里,没变化.
2 string content = Request.Form["content1"].ToString();
Response.Write(content);
string b = Request.Form["txtUserName"].ToString();
Response.Write("<br>"+b);
此时输出是正确的.即可以接收到提交页面提交的数据. 展开
string content = Request.Form["content1"].ToString();//用来接收文本编辑器提交的文本(包括其格式)
string b = Request.Form["txtUserName"].ToString();//用来接收提交过来的编号
string dbpath2 = System.Configuration.ConfigurationSettings.AppSettings["dbpath"];
OleDbConnection conn2 = new OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;Data source=" + Server.MapPath(dbpath2));
conn2.Open();
string str = "update xianlu set richengshisu = @neirong where bianhao = @biaoti";
Response.Write(str);
OleDbCommand cmd1 = new OleDbCommand();
OleDbParameter biaoti = new OleDbParameter("@biaoti", OleDbType.VarChar);
biaoti.Value = b;
OleDbParameter neirong = new OleDbParameter("@neirong", OleDbType.VarChar);
neirong.Value = content;
cmd1.CommandText = str;
cmd1.Connection = conn2;
cmd1.Parameters.Add(biaoti);
cmd1.Parameters.Add(neirong);
try
{
cmd1.ExecuteNonQuery();
Response.Write("<br>"+str);
Response.Write("<script>alert('添加成功!');</script>");
Response.Write("<script>location.replace('../xianlu.aspx');</script>");
}
catch (OleDbException ex)
{
Response.Write("添加失败!"+ex.Message);
}
conn2.Close();
cmd1.Connection.Close();
cmd1.Dispose();
我用的是ACCESS数据库,richengshisu在数据库中的数据类型为备注,bianhao在数据库中的数据类型为文本。
Response.Write(str);的输出为:
update xianlu set richengshisu = @neirong where bianhao = @biaoti
Response.Write("<br>"+str);的输出为:
update xianlu set richengshisu = @neirong where bianhao = @biaoti
我也不知道应咋办了,伤心死了。弄了一晚上。有意者百度HI吧。伤心!绝望!……
---------谁来给我希望
有意者百度HI我吧.凌晨2点前在线.
俺并不是非要用这种方法,用其它方法也行,只要能实现这个要求.
1 当我在文本编辑器中,输入正确的编号和内容时,总是提示"添加成功",可到数据库里,没变化.
2 string content = Request.Form["content1"].ToString();
Response.Write(content);
string b = Request.Form["txtUserName"].ToString();
Response.Write("<br>"+b);
此时输出是正确的.即可以接收到提交页面提交的数据. 展开
2个回答
展开全部
我以前也遇到过这个问题~非常的郁闷~
不过也确实不用在这一棵树上吊死~~
可以直接用拼SQL字符串的方法来实现~
我帮你改了一下!!
string content = Request.Form["content1"].ToString();//用来接收文本编辑器提交的文本(包括其格式)
string b = Request.Form["txtUserName"].ToString();//用来接收提交过来的编号
string dbpath2 = System.Configuration.ConfigurationSettings.AppSettings["dbpath"];
OleDbConnection conn2 = new OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;Data source=" + Server.MapPath(dbpath2));
conn2.Open();
string str =string.Format("update xianlu set richengshisu='{0}' where bianhao={1}",content,b); //用 format 方法拼接字符串
Response.Write(str);
OleDbCommand cmd1 = new OleDbCommand();
cmd1.CommandText = str;
cmd1.Connection = conn2;
try
{
int i=cmd1.ExecuteNonQuery();
Response.Write("<br>" + str);
Response.Write("<script>alert('添加成功!');</script>");
Response.Write("<script>location.replace('../xianlu.aspx');</script>");
}
catch (OleDbException ex)
{
Response.Write("添加失败!" + ex.Message);
}
conn2.Close();
cmd1.Connection.Close();
cmd1.Dispose();
不过也确实不用在这一棵树上吊死~~
可以直接用拼SQL字符串的方法来实现~
我帮你改了一下!!
string content = Request.Form["content1"].ToString();//用来接收文本编辑器提交的文本(包括其格式)
string b = Request.Form["txtUserName"].ToString();//用来接收提交过来的编号
string dbpath2 = System.Configuration.ConfigurationSettings.AppSettings["dbpath"];
OleDbConnection conn2 = new OleDbConnection("Provider=Microsoft.jet.OLEDB.4.0;Data source=" + Server.MapPath(dbpath2));
conn2.Open();
string str =string.Format("update xianlu set richengshisu='{0}' where bianhao={1}",content,b); //用 format 方法拼接字符串
Response.Write(str);
OleDbCommand cmd1 = new OleDbCommand();
cmd1.CommandText = str;
cmd1.Connection = conn2;
try
{
int i=cmd1.ExecuteNonQuery();
Response.Write("<br>" + str);
Response.Write("<script>alert('添加成功!');</script>");
Response.Write("<script>location.replace('../xianlu.aspx');</script>");
}
catch (OleDbException ex)
{
Response.Write("添加失败!" + ex.Message);
}
conn2.Close();
cmd1.Connection.Close();
cmd1.Dispose();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询