如何从数据库更新密码top(textbox.Text)行数 [英] How to update Password top (textbox.Text) quantity of rows from database
本文介绍了如何从数据库更新密码top(textbox.Text)行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我有一个文本框。我想从数据库中更新我在文本框中写入的数量的行数。我该怎么做请告诉查询
解决方案
Re:解决方案1.
这是非常非常危险的!
因为您不能将ORDER BY与UPDATE命令一起使用,并且SQL可以自由地按任何顺序处理行,除非给出特定的顺序,否则您无法保证哪些行将被更新。它可能现在可以工作,然后在生产中以惊人的方式失败。
更好的解决方案是使用光标,如下所述:http://stackoverflow.com/questions/3439110/sql-server-update-a-table -by-using-order-by [ ^ ]
跟随C#语句可能有帮助
sting查询= update top( + txtbox1.Text + )TableName set Password =' + txtPassword.Text + '
所以假设你已经在txtbox1中输入了5,在txtPassword中输入了abc然后
查询将是
update top ( 5 )TableName set 密码= ' abc'跨度>
Hello,
I have a Text box. I want to Update that quantity of rows from the database the amount I write in the textbox. how will I do it. Please tell the query
解决方案
Re: Solution 1.
This is very, very dangerous!
Because you cannot use ORDER BY with an UPDATE command, and SQL is at liberty to process rows in any order unless a specific order is given, you can't guarantee which rows will be updated at all. It may work now, and then fail in spectacular ways in production.
A better solution is to use a cursor, as explained here: http://stackoverflow.com/questions/3439110/sql-server-update-a-table-by-using-order-by[^]
following C# statement may help
sting Query = "update top (" + txtbox1.Text + ") TableName set Password = '" + txtPassword.Text + "' "
so lets say you have entered 5 in txtbox1 and "abc" in the txtPassword then
Query would be
update top (5) TableName set Password = 'abc'
这篇关于如何从数据库更新密码top(textbox.Text)行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文