C# Database Bağlantısı
C# DATABASE BAĞLANTISI

CSHARP | Ali Yasin Doğan | 04.02.2019 | 1703

C# Database Bağlantısı Nasıl Olmalı


public static class DBbaglanti
    {

        public static string conString = ConfigurationManager.ConnectionStrings["DBBaglanti"].ConnectionString;
        public static bool ExecuteNonQuery(SqlCommand komut)
        {
            try
            {
                return komut.ExecuteNonQuery() > 0;
            }
            catch (Exception ex)
            {
                string hataOlustu = ex.Message;
                return false;
            }
        }

  
    }


//Kullanımı
 public bool KullaniciEkle(Kullanici _kullanici)
        {
            
                using (SqlConnection con = new SqlConnection(DBbaglanti.conString))
                {
                    using (SqlCommand komut = new SqlCommand("sp_Ekle", con))
                    {
                        con.Open(); 
			komut.CommandType = CommandType.StoredProcedure;
                        komut.Parameters.AddWithValue("@AdSoyad", _kullanici.AdSoyad);
                        return DBbaglanti.ExecuteNonQuery(komut);
                    }
                }
             
        }
  




 Etiketler:  csharp bağlantı connectionstring