I am creating a small program where the value of the radiobutton will be added into the database (gender: male and female.) But it has an error saying "use of unassigned local variable" on the "gender" that must be inserted into the database. Any help will be appreciated.
here is my code:
private void button1_Click(object sender, EventArgs e)
{
Connection();
sql_connect.Open();
try
{
string gender;
if (radioButton_Female.Checked)
{
gender = "Female";
}
if (radioButton_Male.Checked)
{
gender = "Male";
}
sql_command = new MySqlCommand("insert into tbl_sample (gender) values ('" + gender + "')", sql_connect); //here
sql_command.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
sql_connect.Close();
MessageBox.Show("Added!");
}