Code:
MySqlCommand Command = new MySqlCommand("INSERT INTO accounts(AccountID,LogonType) VALUES ('" + fillBox.Text + "','3')", Connection);
~Bas
MySqlCommand Command = new MySqlCommand("INSERT INTO accounts(AccountID,LogonType) VALUES ('" + fillBox.Text + "','3')", Connection);
Quote:
MySqlCommand cmd = new MySqlCommand("SELECT * FROM `accounts` WHERE `AccountID` = "'" + fillBox.Text + "'", Connection);
MySqlDataReader rdr = cmd.ExecuteReader();
bool exist = false;
if (rdr.Read())
exist = true;
if (!exist)
{
Your code goes here.
}
private bool Check(string acc)
{
bool exists = false;
MySqlCommand Command = new MySqlCommand("SELECT * FROM `accounts` WHERE `AccountID` = \"" + acc + "\"", Connection);
MySqlDataReader DR = Command.ExecuteReader(CommandBehavior.CloseConnection);
while (DR.Read())
{
if (Convert.ToString(DR["AccountID"]) == acc)
exists = true;
}
DR.Close();
Command.Dispose();
return exists;
}
private void button1_Click(object sender, EventArgs e)
{
string acc = fillBox.Text;
if (acc != "")
if (!Check(acc))
{
MySqlCommand Command = new MySqlCommand("INSERT INTO accounts(AccountID,LogonType) VALUES ('" + acc + "','3')", Connection);
Command.ExecuteNonQuery();
Command.Connection.Close();
Command.Connection.Dispose();
Command.Dispose();
MessageBox.Show("AccountID created");
}
else
{
MessageBox.Show("AccountID already taken");
}
}