locked
Using MySQL in C# RRS feed

  • Question

  • I am creating an application in C# that will allow Admin's to easily delete users from a SQL database. I have created a login but want to create an admin form. I want to have some feature in the form that will allow Admin's to delete a specific user. The fields in my table are ID, password (md5 hash), username and email.

    Thanks and I hope you can help

    Friday, October 28, 2011 9:28 PM

Answers

  • This might help you.
    aelassas.free.fr
    • Marked as answer by Allen_MSDN Friday, November 4, 2011 7:03 AM
    Saturday, October 29, 2011 1:18 AM
  • For working with mysql you have download mysql client from mysql site. use following link to download

    http://dev.mysql.com/downloads/connector/net/

    for tutorial u can check following link

    http://www.codeproject.com/KB/database/MySQLCsharp.aspx

    http://bitdaddys.com/MySQL-ConnectorNet.html

     

    Hope these will help you.


    Hasibul Haque,MCC,MCPD blog.e-rains.com
    • Marked as answer by Allen_MSDN Friday, November 4, 2011 7:03 AM
    Saturday, October 29, 2011 9:54 AM
  • Hi AmazingAlex,

        Please download MySql Connector/Net firstly and then include the MySql.Data.dll to your project. Write a delete method like this:

         public void DeleteUser(int id)
            {
                using(MySqlConnection con = new MySqlConnection("your connection string"))
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    string sql = "delete from Users where id=@id";
                    cmd.Connection = con;
                    cmd.CommandText = sql;
                    cmd.Parameters.Add(new MySqlParameter("@id", id));
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                       
                    }
                }
            }

        When you want to delete a user, you only need to call the method.

        Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 1, 2011 3:15 AM

All replies

  • This might help you.
    aelassas.free.fr
    • Marked as answer by Allen_MSDN Friday, November 4, 2011 7:03 AM
    Saturday, October 29, 2011 1:18 AM
  • For working with mysql you have download mysql client from mysql site. use following link to download

    http://dev.mysql.com/downloads/connector/net/

    for tutorial u can check following link

    http://www.codeproject.com/KB/database/MySQLCsharp.aspx

    http://bitdaddys.com/MySQL-ConnectorNet.html

     

    Hope these will help you.


    Hasibul Haque,MCC,MCPD blog.e-rains.com
    • Marked as answer by Allen_MSDN Friday, November 4, 2011 7:03 AM
    Saturday, October 29, 2011 9:54 AM
  • Hi AmazingAlex,

        Please download MySql Connector/Net firstly and then include the MySql.Data.dll to your project. Write a delete method like this:

         public void DeleteUser(int id)
            {
                using(MySqlConnection con = new MySqlConnection("your connection string"))
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    string sql = "delete from Users where id=@id";
                    cmd.Connection = con;
                    cmd.CommandText = sql;
                    cmd.Parameters.Add(new MySqlParameter("@id", id));
                    try
                    {
                        con.Open();
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                       
                    }
                }
            }

        When you want to delete a user, you only need to call the method.

        Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 1, 2011 3:15 AM