Index was outside the bounds of the array c# so confusing : Hello Ladies And Gentlemen goodevening to all, may i ask ? how can i get error for this ? it is so confusing i get bug like this i try to fix it many hours but not work at all sorry for being noob coding im just newbie 



    namespace WindowsFormsApp1
{
    public partial class Schedule : Form
    {
        public Schedule()
        {
            InitializeComponent();
        }
        MySqlConnection con = new MySqlConnection(@"Data Source=localhost;port=3306;Initial Catalog=Payroll;User Id=root;password=''");
        MySqlDataReader dr;
        int tc = 0;
        private void Schedule_Load(object sender, EventArgs e)
        {
            datagrid();
            fillsched();
            
        }
        public void datagrid()
        {
            con.Open();
            MySqlDataAdapter sda = new MySqlDataAdapter("Select * from employee where Pstatus='Active'", con);
            DataTable data = new DataTable();
            sda.Fill(data);
            dataGridView1.DataSource = data;
            con.Close();
        }
        public void fillsched()
        {
            con.Open();
            MySqlDataReader dr;
            MySqlCommand cmd = new MySqlCommand("select * from updateschedule ", con);
            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                int data = dr.GetInt32("empSched");
                comboBox1.Items.Add(data);
            }
            con.Close();
        }
        public void getsched()
        {

            if (Int32.TryParse(comboBox1.SelectedItem.ToString(), out tc))
            {
                con.Open();
                MySqlCommand cmd = new MySqlCommand("select * from updateschedule where empSched=@empSched ", con);
                cmd.Parameters.Add("@empSched", MySqlDbType.Int32).Value = tc;
                dr = cmd.ExecuteReader();

                if (dr.Read())
                {
                    textBox2.Text = dr["TimeIn"].ToString();
                    textBox3.Text = dr["TimeOut"].ToString();
                    label5.Text = tc.ToString();//to pass the data in the combobox1
                }
                con.Close();
            }
        }
        public void view()
        {
            textBox1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            getsched();
        }

        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex >= 0)
            {

                view();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            insert();
            insertempsched();
        }
        public void insert()
        {
           
            
                MySqlCommand cmd = new MySqlCommand("INSERT INTO schedule (empSchedID,empID,empIN,empOut)VALUES(@empSchedID,@empID,@empIn,@EmpOut)", con);
                cmd.Parameters.Add("@empSchedID", MySqlDbType.Int32).Value = label5.Text;
                cmd.Parameters.Add("@empID", MySqlDbType.VarChar).Value = textBox1.Text;
                cmd.Parameters.Add("@empIn", MySqlDbType.Date).Value = textBox2.Text;
                cmd.Parameters.Add("@empOut", MySqlDbType.VarChar).Value = textBox3.Text;
                execnonquery(cmd, "Data Inserted");
            
        }
        public void insertempsched()
        {
            
                con.Open();
                MySqlCommand cmd = new MySqlCommand("Update employee set empSched=empSched where empID=@empID", con);
                cmd.Parameters.Add("@empSchedID", MySqlDbType.Int32).Value = label5.Text;
                cmd.Parameters.Add("@empID", MySqlDbType.VarChar).Value = textBox1.Text;
                cmd.ExecuteNonQuery();
                con.Close();
            
        }
        public void execnonquery(MySqlCommand sqc, string mymsg)
        {
            con.Open();
            if (sqc.ExecuteNonQuery() == 1)
            {
                MessageBox.Show(mymsg);
            }
            else
            {
                MessageBox.Show("Query not Executed");
            }
            con.Close();
        }
    }
}
