コード例 #1
0
ファイル: OgrenciBL.cs プロジェクト: hlmyngn/deneme2
        public static bool OgrenciDersEkle(OgrenciDersleri secilenDers)
        {
            bool eklendi = false;
            MySqlConnection connection = null;
            try
            {
                string connectionString = "SERVER=localhost;DATABASE=OgrenciYonetimSistemi; UID=root;PASSWORD=hy050491;";

                connection = new MySqlConnection(connectionString);

                connection.Open();

                string query = " INSERT INTO ogrencidersleri (Ogrenci,Ders) VALUES('" + secilenDers.Ogrenci.Id + "','" + secilenDers.Ders.Id + "')";

                //create command and assign the query and connection from the constructor
                MySqlCommand cmd = new MySqlCommand(query, connection);

                int sonucDeger = cmd.ExecuteNonQuery();
                if (sonucDeger > 0)
                    eklendi = true;
            }
            catch (Exception ex)
            {
                eklendi = false;
            }
            finally
            {
                connection.Close();
            }
            return eklendi;
        }
コード例 #2
0
ファイル: OgrenciBL.cs プロジェクト: hlmyngn/deneme2
        public static List<OgrenciDersleri> OgrenciDersGetir(Ogrenci ogrenci)
        {
            List<OgrenciDersleri> ogrenciDersleri = new List<OgrenciDersleri>();
            MySqlConnection connection=null;
            try
            {
                string connectionString="SERVER=localhost;DATABASE=OgrenciYonetimSistemi; UID=root;PASSWORD=hy050491;";
                 connection = new MySqlConnection(connectionString);
                connection.Open();
                string query = "SELECT * FROM OgrenciDersleri";

                MySqlCommand cmd = new MySqlCommand(query, connection);
                MySqlDataReader reader= cmd.ExecuteReader();

                while (reader.Read())
                {
                    OgrenciDersleri ogreciDers = new OgrenciDersleri();
                    ogreciDers.Id = Convert.ToInt32(reader["Id"]);

                    ogreciDers.Ogrenci = new Ogrenci();
                    ogreciDers.Ogrenci.Id = Convert.ToInt32(reader["Ogrenci"]);
                    ogreciDers.Ders = new Ders();

                    ogreciDers.Ders.Id = Convert.ToInt32(reader["Ders"]);

                    string studentQuery = "SELECT * FROM Ogrenci WHERE Id = '" + ogreciDers.Ogrenci.Id + "'";

                    MySqlCommand cmdStudent = new MySqlCommand(query, connection);
                    MySqlDataReader readerStudent = cmd.ExecuteReader();
                    while (readerStudent.Read())
                    {
                        ogreciDers.Ogrenci.Adi = readerStudent["Adi"].ToString();
                        ogreciDers.Ogrenci.Soyadi = readerStudent["Soyadi"].ToString();
                    }

                    ogrenciDersleri.Add(ogreciDers);
                }
                connection.Close();
                    DataTable table = new DataTable();
                    table.Load(reader);
                    for (int i = 0; i < table.Rows.Count; i++)
                {
                    string adi = table.Rows[i]["Id"].ToString();
                }
                //DersBilgileriDoldur(ogrenciDersleri);
            }
            catch (Exception ex)
            {

            }
            finally
            {
                connection.Close();
            }
            return ogrenciDersleri;
        }
コード例 #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     Ders secilenDers = dgvDersListesi.SelectedRows[0].DataBoundItem as Ders;
     if (secilenDers != null)
     {
         OgrenciDersleri yeniDers = new OgrenciDersleri();
         yeniDers.Ogrenci = _ogrenci;
         yeniDers.Ders = secilenDers;
         OgrenciBL.OgrenciDersEkle(yeniDers);
     }
 }