I have this code, when I run the select query only it works. When I run the insert query only also it works. but the two queries can't work at the same time. I don't know what's the problem???! can you help me
public partial class signUpFM : Form
{
String str = @"server=localhost;database=Bullivant_Arabia_Archive;userid=root;password='';";
MySqlConnection con = null;
MySqlCommand cmd = null;
public signUpFM()
{
InitializeComponent();
}
private void signUpBT_Click(object sender, EventArgs e)
{
try
{
con = new MySqlConnection(str);
con.Open();
if(checkUser(userNameTB.Text))
{
if (password1TB.Text == password2TB.Text)
{
insertUser(this.userNameTB.Text, this.password1TB.Text);
}
else
{
MessageBox.Show("You haven't enter the same password twice");
}
}
else
{
MessageBox.Show("The user name already exist, please enter another one!");
}
}
catch (MySqlException err)
{
Console.WriteLine("Error: " + err.ToString());
}
finally
{
if (con != null)
{
con.Close();
}
}
}
public void insertUser(String userName, String password)
{
String userQuery = @"insert into login (Username,Password) values ('" + userName + "' , '"
+ password + "')";
if (executeInsertQuery(userQuery))
MessageBox.Show("Sign up have been completed");
else
MessageBox.Show("Sign up couldn't be completed");
}
bool checkUser (String UserName)
{
String Query = @"select * from login where UserName = '" + UserName + "'";
if (executeSelectQuery(Query))
return false;
else return true;
}
bool executeSelectQuery(String query)
{
cmd = new MySqlCommand(query, con);
if (cmd.ExecuteReader().Read())
return true;
else return false;
}
bool executeInsertQuery(String query)
{
cmd = new MySqlCommand(query, con);
if (cmd.ExecuteNonQuery() == 1)
return true;
else return false;
}