コード例 #1
0
        private void Kaydet_button(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(adtext.Text) || !string.IsNullOrEmpty(adtext.Text) || !string.IsNullOrEmpty(numberText.Text))
            {
                ad          = adtext.Text;
                soyad       = soyadtext.Text;
                kullaniciNo = int.Parse(numberText.Text);                                                                                                                                          //Değişkene textboxtaki veriler kaydedildi
                OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Omura\\source\\repos\\stajokuluproje\\stajokuluproje\\StajOkuluDatabase.mdb"); //Veritabanı çekiliyor
                conn.Open();                                                                                                                                                                       //veriytabanı bağlantısı açıldı
                String Sorgu = "INSERT INTO Kullanici(KullaniciNo,Ad,Soyad)VALUES('" + kullaniciNo + "','" + ad + "','" + soyad + "')";                                                            //Veritabanına ekleme yapılıyor
                try
                {
                    //Hata yok ise sorgu çalıştırılacak komutu
                    OleDbCommand cmd = new OleDbCommand(Sorgu, conn);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show(text: "Giriş başarılı!", caption: "Durum!", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Asterisk);

                    HASTALIK_SECİMİ nextPage = new HASTALIK_SECİMİ(kullaniciNo);
                    nextPage.Show();
                    this.Hide();//Giriş başarılı ise diğer sayfaya girebilsin
                }
                catch (Exception ex)
                {
                    //kayıt eklenemediğinde verilen hata
                    MessageBox.Show(text: "Giriş Başarısız!", caption: "Durum!", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error);
                }
                conn.Close();
            }
        }