在ASP.NET和C#中增加价值 [英] Incrementing value in ASP.NET and C#

查看:58
本文介绍了在ASP.NET和C#中增加价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从数据库中检索一个int类型的值并将其值增加1,那么如何在ASP.NET和C#中发生这种情况?到数据库,然后执行一个非查询(ExecuteNonQuery),该查询将增加数据库中的值(您将使用UPDATE SQL语句).


很难理解您的目标需求,但是如果您只想获取数据库值,然后在数据库中增加1,然后像AspDotNetDev所建议的那样,则可以在单个语句中进行操作.

Update MyTable SET MyValue = MyValue + 1; Select MyValue - 1 AS ReturnValue FROM MyTable;



在这里,您可以对Scaler执行此查询,并且在一次数据库往返中就可以实现您的目标.

问候
鲁西


i want to retrieve an int type value from database and increment its value by 1,how this can be happened in ASP.NET and C#?

解决方案

Connect to the database, then execute a non-query (ExecuteNonQuery) that increments the value in the database (you will use an UPDATE SQL statement).


It''s hard to understand your end requirement but if you just want to get Database value and then increase by 1 in Database then like sugested by AspDotNetDev you can do in a single statement.

Update MyTable SET MyValue = MyValue + 1; Select MyValue - 1 AS ReturnValue FROM MyTable;



Here you can execute this query for Scaler, and in one DB roundtrip you can achieve your goal.

Regards
Rushi


这篇关于在ASP.NET和C#中增加价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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