Hi,

I would like to check if some records exist in MySQL database and if they are missing I want to add some alternative information. I tried to use the following code but made a mistake. I am a beginner in c# and not sure how to do that. Please could you tell me what the problem is:

Thanks
telmessos

Code:
private void button1_Click(object sender, EventArgs e)
        {
            for (int has = 1; has <= 10; has++)
            {
                for (int ted = 1; ted <= 15; ted++)
                {
                    for (int cin = 1; cin <= 20; cin++)
                    {
                        for (int yas = 1; yas <= 100; yas++)
                        {
                            connection.Open();
                            String testsql = "Select * from v2007 where HASTALIK_GRUBU='" + has + "' and TEDAVI_ILI='" + ted + "' and CINSIYET='" + cin + "' and YAS='" + yas + "'";
                            MySqlCommand testcommand = new MySqlCommand();
                            testcommand.CommandText = testsql;
                            testcommand.ExecuteNonQuery();
                            MySqlDataAdapter adapter2 = new MySqlDataAdapter();
                            adapter2.SelectCommand = testcommand;
                            DataTable dataset = new DataTable();
                            adapter2.Fill(dataset);
                            if (dataset.Rows.Count == 0)
                            {
                                String sql2 = "Insert into v2007(HASTALIK_GRUBU,TEDAVI_ILI,CINSIYET,YAS,AYAKTA,YATARAK) values('" + has + "','" + ted + "','" + cin + "','" + yas + "','0','0')";
                                MySqlCommand command2 = new MySqlCommand();
                                command2.CommandText = sql2;
                                command2.ExecuteNonQuery();
                            }
                            connection.Close();
                        }
                    }
                }
            }
            label2.Text = "İşlem bitti";
        }