删除需要密码的用户 [英] Delete User Requiring A Password
本文介绍了删除需要密码的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果要删除用户但需要在SQL表中键入分配给该用户的确切密码,我应该使用什么代码以及在哪里使用
已添加注释:该按钮可完美删除用户,但我也插入了一个txtbox密码,希望系统在删除用户之前先要求输入密码
What code and where should I use if I want to delete a user but requires to type in the precise password assigned to that user in SQL Table
Comment Added: the button work on deleting the user perfectly, but I also inserted a txtbox of password and want the system to require a password first before just deleting the user
推荐答案
bool match = false;
public void delmethod()
{
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
SqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT * FROM YOURTABLE";
SqlDataReader dataread = command.ExecuteReader();
while (dataread.Read() && located != true)
{
if (textBox1.Text == dataread["PRECISEPASSWORD"].ToString())
{
match = true;
}
else
{
match = false;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
delmethod(); //calls for the delete method
if (match == true) //registered user found
{
SqlConnection connection = new SqlConnection(ConnectionString.Conn);
connection.Open();
SqlCommand asd = connection.CreateCommand();
asd.CommandText = "DELETE FROM YOUTRABLE WHERE Username =''" + YOURUSERNAME + "''";
asd.ExecuteNonQuery();
connection.Close();
}
这应该有助于您的需求.如有其他疑问,请随时询问.
This should help with what you need. Any other questions don''t hesitate to ask.
您自己写下了任何代码吗?
我假设您应该有一个按钮来触发事件,打开sql连接,创建sql命令并执行它. sql命令应包含delete语句.
设置WHERE ="precisepassword"吗?
Do you have any code written down yourself?
I''m assuming you should have a button to trigger the event, open the sql connection, create an sql command and execute it. the sql command should contain the delete statement.
set the WHERE = ''precisepassword'' maybe?
这篇关于删除需要密码的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文