Results 1 to 5 of 5

Thread: Mysql

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2010
    Posts
    63

    Mysql

    Code:
    public bool LoginAccount(string username, string password)
            {
                string query = "SELECT * FROM login where userid = '" + username + "'";
                string _dbReader;
                bool _check = false;
                //Open connection
                if (this.OpenConnection() == true)
                {
                    //Create Command
                    MySqlCommand cmd = new MySqlCommand(query, connection);
                    //Create a data reader and Execute the command
                    MySqlDataReader dataReader = cmd.ExecuteReader();
    
                    //Read the data and store them in the list
                    if (dataReader.HasRows)
                    {
                        if (dataReader.Read())
                        {
                            _dbReader = Convert.ToString(dataReader["user_pass"]);
                            _accountid = Convert.ToInt32(dataReader["account_id"]);
                            if (_dbReader == password)
                            {
                                _check = true;
                            }
                            else
                            {
                                MessageBox.Show("Incorrect password.");
                            }
                        }
                    }
                    else
                    {
                        _check = false;
                        MessageBox.Show("Account not found", username, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    //close Data Reader
                    dataReader.Close();
                    //close Connection
                    this.CloseConnection();
                }
                else
                {
                    _check = false;
                    MessageBox.Show("Server is closed.");
                }
                return _check;
            }
    
            //Create Character
            public bool CreateCharacter(string name, string job)
            {
                bool _check = false;
                try
                {
                    string query = "INSERT INTO characters (account_id, name, class) VALUES('" + _accountid + "' ,'" + name + "' ,'" + job + "')";
                    //open connection
                    if (this.OpenConnection() == true)
                    {
                        //create command and assign the query and connection from the constructor
                        MySqlCommand cmd = new MySqlCommand(query, connection);
                        //Execute command
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("Create Successful.");
                        _check = true;
                    }
                }
                catch (Exception ex)
                {
                    _check = false;
                    if (ex.Message.IndexOf("name") >= 0)
                        MessageBox.Show("That Character already exists. Please change the Character Name.");
                    else
                        MessageBox.Show(ex.Message);
                }
                finally
                {
                    //close connection
                    this.CloseConnection();
                }
                return _check;
            }
    im confus about insert _account_id it's always 0 when passing value
    Last edited by solid2005; Jul 25th, 2010 at 05:58 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width