在c#.net中使用sql更新查询的奇怪输出 [英] strange output in using sql update query in c#.net

查看:62
本文介绍了在c#.net中使用sql更新查询的奇怪输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我必须在Access的表中的一个字段中更改数据.
我使用更新查询.
但是查询仅从表中删除旧数据,而没有输入带有foll代码的新数据.
代码:

Hello everyone,
I have to change the data in one of the fields in my table in access.
I use the update query.
but the query only deleting the old data from the table and not entering the new data with the foll code.
code:

String esql = string.Format("update company_list SET company_name ='{0}' where company_name ='{1}'", edited_name, selected_name);
OleDbCommand myupdate = new OleDbCommand(esql, con);
myupdate = new OleDbCommand(esql, con);
myupdate.ExecuteNonQuery();




因此,我尝试更改代码,但是在这里,它说@new_name必须具有默认值.
但是如何设置默认值

代码:




so, I try to change the code, but here, it says that @new_name must have a default value.
but how to set a default value

code:

using (OleDbCommand myupdate = con.CreateCommand())
             {
 myupdate.CommandText = "update company_list set company_name = @new_name where company_name = @old_name";
                 
                 myupdate.Parameters.AddWithValue("@new_name",edited_name);
                 myupdate.Parameters.AddWithValue("@old_name", selected_name);
                 
                 myupdate.ExecuteNonQuery();
}



请尽快提供帮助.



Please help asap.

推荐答案

检查edited_name的值-可能为空或为null,这就是为什么要抱怨的原因.以及为什么删除原始危险代码而不进行替换.
Check the value of edited_name - it is probably blank or null, which is why it is complaining. And why the original, dangerous code deleted without replacing.


edited_name为空或为空.确保确实将新名称添加到该变量中.
edited_name is null or empty. Make sure that you really get the new name into that variable.


这篇关于在c#.net中使用sql更新查询的奇怪输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆