Data Inserting Through Selected Radio and checkbox button

Mohamed Rafi N 106 Reputation points
2022-03-26T08:40:54.247+00:00

Sir, in this code, if i click bad radio button2 and untaste checkbox2 means data inserting only radio button1 and taste checkbox1 that is good and tasty itself inserting in database sir

if (!string.IsNullOrEmpty(textBox11.Text) && !string.IsNullOrEmpty(textBox12.Text) && !string.IsNullOrEmpty(textBox13.Text) && !string.IsNullOrEmpty(textBox14.Text) && (radioButton1.Checked || radioButton2.Checked) && (checkBox1.Checked || checkBox2.Checked))
{
string connectionString;
MySqlConnection cnn;
connectionString = @"Data Source=localhost;Initial Catalog=testDB;User ID=root;Password=mysql";
cnn = new MySqlConnection(connectionString);
cnn.Open();
string id = textBox14.Text;
string name = textBox11.Text;
string year = textBox12.Text;
string quality = radioButton1.Text == "" ? radioButton2.Text : radioButton1.Text;
string taste = checkBox1.Text == "" ? checkBox2.Text : checkBox1.Text;
string sales = textBox13.Text;
textBox11.Text = "";
textBox12.Text = "";
textBox13.Text = "";
textBox14.Text = "";
radioButton1.Text = "";
radioButton2.Text = "";
checkBox1.Text = "";
checkBox2.Text = "";
string query = "INSERT INTO fruits VALUES(@fruitsid, @fruitsname, @fruitsyear, @quality, @taste, @Sales )";
using (MySqlCommand cmd = new MySqlCommand(query))
{
cmd.Parameters.AddWithValue("@fruitsid", Convert.ToInt32(id));
cmd.Parameters.AddWithValue("@fruitsname", name);
cmd.Parameters.AddWithValue("@fruitsyear", year);
cmd.Parameters.AddWithValue("@quality", quality);
cmd.Parameters.AddWithValue("@taste", taste);
cmd.Parameters.AddWithValue("@Sales ", sales);
cmd.Connection = cnn;
cmd.ExecuteNonQuery();
MessageBox.Show("Record Inserted Successfully");
DisplayData();
cnn.Close();
}
}
else
{
MessageBox.Show("Please Fill Data");
}

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,866 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,535 questions
{count} votes