Click here to Skip to main content
15,909,827 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 25-May-11 18:28pm
v2

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.
 
Share this answer
 
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?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900