使用命名参数减少值不会更改所述值 [英] Decreasing a value with a named parameter doesn't change said value

查看:53
本文介绍了使用命名参数减少值不会更改所述值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想减小Access数据库中的urunadedi值.我有以下代码:

I want to decrease my urunadedi value in an Access database. I have the following code:

cmd2.Connection = con;
cmd2.Parameters.AddWithValue("@urunid", Convert.ToInt64(textBox1.Text));
cmd2.Parameters.AddWithValue("@hesaplam",Convert.ToInt64(textBox2.Text));
cmd2.CommandText = @"UPDATE Table1
                     SET urunadedi=urunadedi-@hesaplam
                     WHERE urunadi=@urunid";
cmd2.ExecuteNonQuery();

但是字段urunadedi的值没有减少.为什么会这样,我该如何解决?

But the value of the field urunadedi is not decreasing. Why is that and how can I solve that?

urunadedi , urunid urunadi 为非土耳其语读者带来了方便,将其大致翻译为 ProductName ,和 hesaplam 大致翻译为计算.

For the benefit of non-Turkish readers, urunadedi, urunid and urunadi translate roughly as ProductName, and hesaplam translates roughly as calculate.

推荐答案

Microsoft OLEDB 忽略参数名称,仅注意参数出现在 order 中CommandText.所以,对于

Microsoft OLEDB ignores parameter names and only pays attention to the order in which the parameters appear in the CommandText. So, for

cmd2.CommandText = @"UPDATE Table1
                     SET urunadedi=urunadedi-@hesaplam
                     WHERE urunadi=@urunid";

我们需要首先添加@hesaplam参数,因为它首先出现在CommandText中

we need to add the @hesaplam parameter first since it appears first in the CommandText

cmd2.Parameters.AddWithValue("@hesaplam", Convert.ToInt64(textBox2.Text));
cmd2.Parameters.AddWithValue("@urunid", Convert.ToInt64(textBox1.Text));

还请注意,由于忽略了OLEDB参数名称,因此很常见地看到问号(?)被用作参数占位符:

Note also that because the OLEDB parameter names are ignored it is quite common to see the question mark (?) being used as the parameter placeholder:

cmd2.CommandText = @"UPDATE Table1
                     SET urunadedi=urunadedi-?
                     WHERE urunadi=?";
cmd2.Parameters.AddWithValue("?", Convert.ToInt64(textBox2.Text));  // @hesaplam
cmd2.Parameters.AddWithValue("?", Convert.ToInt64(textBox1.Text));  // @urunid

这篇关于使用命名参数减少值不会更改所述值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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