cmd.CommandText = "update 学生 SET 中文姓名=@chname where id =@urlid";
int urlid = Convert.ToInt32(lblid.Text);
cmd.Parameters.AddWithValue("@urlid", urlid); cmd.Parameters.AddWithValue("@chname", txbchname.Text);
我在一个网页中用上面的代码试图对数据库更新。更新的数据从文本框txbchname中输入,但没办法实现对数据库的更新,网页也不报任何错误。
我把代码改成下面这样就可以了 cmd.CommandText = "update 学生 SET 中文姓名='haha' where id =@urlid";
int urlid = Convert.ToInt32(lblid.Text);
cmd.Parameters.AddWithValue("@urlid", urlid);
但这样我不能插入要更新的参数啊,求助
解决方案 »
- asp.net sqlserver中的数据导入导出到Excel!!
- 求教一个关于web.sitemap的问题。
- 请问:在一个纯静态网站的html页里调用另一个asp.net网站中一个页面里的datalist的显示内容,能实现吗?
- 100求一个两级分类的高效写法
- [求助]关于web.config文件的配置。。。
- 我怎么样才能得到treeview得节点得text,id
- .ashx文件传值和执行的问题
- 请问编译器显示“无法找到 Imports“system.data.sql”的命名空间或类型“sql””意味着什么?
- 什么叫做占位符
- 简单问题之二!
- FCKeditor怎样显示HTML,javascritp源代码
- 用户 'sa' 登录失败。该用户与可信 SQL Server 连接无关联。
cmd.CommandText = "update 学生 SET 中文姓名=@chname where id =@urlid";
int urlid = Convert.ToInt32(lblid.Text);
cmd.Parameters.AddWithValue("@chname", txbchname.Text);
cmd.Parameters.AddWithValue("@urlid", urlid);
否则不会更新
SqlConnection conn = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand("", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@username", Txtname.Text); conn.Open();
cmd.ExecuteNonQuery(); using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = conn;
cmd.CommandText = "select * from admin where id=@id";
cmd.Parameters.AddWithValue("@id", TextBox1.Text);
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
if (dr.HasRows)
{
}
}
用new SqlParameter
但如果不用参数,比如cmd.CommandText = "update 学生 SET 中文姓名='haha' where id =@urlid";
就没问题。
int urlid = Convert.ToInt32(lblid.Text);
SqlParameter parurlid = new SqlParameter();
parurlid.ParameterName = "@urlid";
parurlid.Value = urlid;
cmd.Parameters.Add(parurlid);
SqlParameter parchname = new SqlParameter("@chname", txbchname.Text);
cmd.Parameters.Add(parchname);
cmd.ExecuteNonQuery();
但我写成这样还是不行啊。
请指教。谢谢。
还有就是用 sqlparameter[] param = new sqlparameter[]
{
new sqlparameter("@chname",txbchname.Text),
new sqlparameter("=@urlid",urlid)
};
然后调用执行方法就可以了
我现在的问题是对数据库就更新不了.
另外我在PAGE_LOAD()里对数据重新执行了查询。应该不会有问题的。我现在就是不能UPDATE。其他的INSERT.SELECT什么的都可以。
不理解啊
如果我的UPDATE语句不带参数也没问题,比如比如cmd.CommandText = "update 学生 SET 中文姓名='haha' where id =@urlid";
一带参数就不能更新了,头大
哪位朋友指点小弟一下
2,断点把参数的值取出来,直接运行SQL语句调试(其实不用调试肯定能更新的)declare @chname nvarchar(50)
declare @urlid int
set @chname = '写值'
set @urlid = 100--改成自己的值
update 学生 SET 中文姓名=@chname where id =@urlid
--执行这个SQL语句看什么结果.3,故意写错SQL语法,看会不会报错,确认你有程序有调用到该SQL...
这位大哥。
第一个问题我没写错;
第二个你给的代码我直接在SQL数据调试了,能够更新。OK的。
第三个,我写错SQL语法。网页报错了但我现在通过网页执行,就不能在数据库中更新了,我查看数据库了。这个是什么问题啊
网页执行极有可能跳过了某些CASE最后没有执行SQL...
cmd.CommandText = "update 学生 SET 中文姓名=@chname where id '78'";