1. Dynamicznie dodaje do TableLayoutPanela PicterBox. Mam na razie ustawione w TableLayoutPanel 4 kolumny i 2
    wiersze,jak ustawić dynamicznie dodawanie kolumn i wierszy w zależności od ilości zdjęć? Tak np jeśli wybiorę 2 zdjęcia to w TableLayoutPanel tworzy tylko 2 kolumny jeśli więcej to tworzy proporcjonalnie np 2:1, czyli 4 kolumny 2 wiersze, albo 8 kolumn 4 wiersze.
  2. Mam bazę w sql server w niej dwie tabele połączone relacją jeden do wielu. Jak na poniższym diagramie:
    user image
    Chcę dodać film który zawiera np 3 gatunki. Ale wyrzuca mi błąd:
    "ExecuteNonQuery requires the command to have a transaction when the
    connection assigned to the command is in pending local transaction. The
    Transaction property of the command has been initialized." Nie wiem jak dokładnie korzystać z transakcji . To mój kod:
string[] linkaddgalerie = {"Komedia","horror","thriller"};
            bool success = true;
            SqlConnection sqlconn = null;
            SqlTransaction trans = null;
            SqlDataReader sqlreader = null;
            try
            {
                sqlconn = new SqlConnection("Data Source=SLAWEK\\SQLSERVER;Initial Catalog=testowa;Integrated Security=True");
                sqlconn.Open();
                trans = sqlconn.BeginTransaction(System.Data.IsolationLevel.Serializable);
 
               using (SqlCommand command1 = new SqlCommand("Insert Into 
film (tytulorginalny,tytul,data) Values ('" + this.tbtytulorginalny.Text
 + "','" + this.tbtytul.Text + "','" + dtp.Value.Date.Year + "/" + 
dtp.Value.Date.Month + "/" + dtp.Value.Date.Day + "')", sqlconn))
                {
                    command1.ExecuteNonQuery();
                }
 
               using (SqlCommand command2 = new SqlCommand("select ID 
from Film where tytulorginalny ='" + this.tbtytulorginalny.Text + "'", 
sqlconn))
                {
                    sqlreader = command2.ExecuteReader();
                }
                for (int i = 0; i < linkaddgalerie.Length; i++)
                {
 
                   using (SqlCommand command3 = new SqlCommand("Insert 
Into galeria (galeria,ID_film) Value ('" + linkaddgalerie[i] + "','" + 
sqlreader + "')", sqlconn))
                    {
                        command3.ExecuteNonQuery();
                    }
                }
                MessageBox.Show("Dodano rekord do bazy!", "Sukces", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (SqlException ex)
            {
                success = false;
                MessageBox.Show("Błąd:" + ex.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                success = false;
                MessageBox.Show("Błąd:" + ex.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (success)
                    trans.Commit();
                else
                    trans.Rollback();

                if (sqlconn != null)
                    sqlconn.Close();
            }

Jak by mógł ktoś podpowiedzieć co źle robię. Nie miałem też dawno do czynienia z sql-em więc tam tez może być błąd..