I have the following code and I would like the code to query the database:
MySqlConnection connection = new MySqlConnection(Connection);
MySqlCommand cmd;
connection.Open();
try
{
cmd = connection.CreateCommand();
cmd.CommandText = ("INSERT INTO edata (username) VALUES ('" + this.NewUserName.Text +"') ;");
MySqlDataReader myReader;
myReader = cmd.ExecuteReader();
loading.Show();
MessageBox.Show("Your Account Has Been Created!!");
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
If the clients input (NewUserName.Text) is the same as the username in the database there should be an error message, otherwise there will be duplicate usernames. How can I do this?
I have already got the connection as a string.
Thank you in advance!!!
PS Im a student learning C# and MySql, I am grateful for any help and advice!