如何通过单击按钮增加存储在数据库中的计数器值? [英] How to increment the counter value that is stored in database on a click of a button ?
本文介绍了如何通过单击按钮增加存储在数据库中的计数器值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
表格中有一个名为Quantity的列。库存中的可用书籍数量存储在此处。从用户取消分配图书时,数量列中的值应增加1.只需单击按钮即可执行取消分配。我该怎么做?
我尝试过:
我没有尝试任何东西。我想过创建一个程序来做到这一点。但我不知道如何在按钮单击中调用该过程..
There is a column named Quantity in the table. the quantity of available books in the inventory is stored here. When a book is de-assigned from a user the value in Quantity column should increase by 1. This de-assign is performed on a click of a button. How do I perform this?
What I have tried:
I have not tried anything. I thought of creating a procedure to do this. But I do not know how to call the procedure in button click..
推荐答案
尝试:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("UPDATE myTable SET Quantity = Quantity + 1 WHERE BookID = @BI", con))
{
cmd.Parameters.AddWithValue("@BI", IdValueForTheRowToSayWhichBookItIs);
cmd.ExecuteNonQuery();
}
}
忘记WHERE条件... [/ EDIT]
Forgot the WHERE condition...[/EDIT]
这篇关于如何通过单击按钮增加存储在数据库中的计数器值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文