C# Form Veritabanı Bağlantısı

static string conString = @"Server=BEKIR\BEKIR; Database=kullanicigirisi; Trusted_Connection=True;";
        SqlConnection baglanti = new SqlConnection(conString);


 private void veritabaninaKaydet()
        {
            try
            {
                if (baglanti.State == ConnectionState.Closed)
                    baglanti.Open();

                string kayit = "insert into kullanici(kullaniciAdi,kullaniciParola,kullaniciMail) values (@kullaniciAdi,@kullaniciParola,@kullaniciMail)";
                SqlCommand komut = new SqlCommand(kayit, baglanti);

                komut.Parameters.AddWithValue("@kullaniciAdi", textBox1.Text);
                komut.Parameters.AddWithValue("@kullaniciParola", textBox2.Text);
                komut.Parameters.AddWithValue("@kullaniciMail", textBox3.Text);

                komut.ExecuteNonQuery();
                MessageBox.Show("Kullanıcı Başarılı Bir Şekilde Eklendi");
                baglanti.Close();

            }
            catch (Exception hata)
            {
                MessageBox.Show("İşlem Sırasında Hata Oluştu." + hata.Message);
            }
            Close();
        }

Hiç yorum yok:

Yorum Gönder