- [ Tüm kodu seç ] [ Yeni Pencerede Göster ]
//Helper Sınıfımız public class Helper { string constr; public Helper(string constr) { this.constr = constr; } public Helper() { constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; } public int ExecuteNonQuery(string sqlstr, CommandType type, SqlParameter[] paramdizi) { SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(sqlstr, con); cmd.CommandType = type; if (paramdizi != null) { cmd.Parameters.AddRange(paramdizi); con.Open(); } try { if (con.State != ConnectionState.Open) con.Open(); return cmd.ExecuteNonQuery(); } catch (SqlException ex) { throw ex; } finally { if (con.State != ConnectionState.Closed) { con.Close(); } } } public object ExecuteScalar(string sqltr, CommandType type, SqlParameter[] paramdizi) { SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(sqltr, con); cmd.CommandType = type; if (paramdizi != null) cmd.Parameters.AddRange(paramdizi); con.Open(); try { if (con.State != ConnectionState.Open) con.Open(); return cmd.ExecuteScalar(); } catch (SqlException ex) { throw ex; } finally { if (con.State != ConnectionState.Closed) con.Close(); } } public SqlDataReader ExecuteReader(string sqltr, CommandType type, SqlParameter[] paramdizi) { SqlConnection con = new SqlConnection(constr); SqlCommand cmd = new SqlCommand(sqltr, con); cmd.CommandType = type; if (paramdizi != null) cmd.Parameters.AddRange(paramdizi); con.Open(); try { if (con.State != ConnectionState.Open) con.Open(); return cmd.ExecuteReader(); } catch (Exception ex) { throw ex; } } }
- [ Tüm kodu seç ] [ Yeni Pencerede Göster ]
Mssql Bağlantısı Web Config <add name="constr" connectionString=" Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\belgeler\Visual Studio 2010\Projects\Yeni\YeniDb.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient"/>
- [ Tüm kodu seç ] [ Yeni Pencerede Göster ]
Default.cs Helper hlp = new Helper() void MagzaGetir() { SqlParameter[] DenemeParameter = new SqlParameter[1] { new SqlParameter("@DenemeDurum",SqlDbType.Int) }; DenemeParameter[0].Value = 1; SqlDataReader dr = hlp.ExecuteReader("Mssql Gelen Store Procedure", CommandType.StoredProcedure, MagzaGetirParameter); List<AdminMagzaGetir> Liste = new List<AdminMagzaGetir>(); while (dr.Read()) { AdminMagzaGetir info = new AdminMagzaGetir(dr.GetInt32(0), dr.GetString(1)); Liste.Add(info); drpKategoriEkleMagza.DataSource = Liste; } drpdeneme.DataTextField = "MagzaAdi"; drpdeneme.DataValueField = "MagzaID"; drpdeneme.DataBind(); MagzaCount = Liste.Count.ToString(); }
- [ Tüm kodu seç ] [ Yeni Pencerede Göster ]
// AdminMagzaGetir Sınıfı public class AdminMagzaGetir { int magzaID; public int MagzaID { get { return magzaID; } set { magzaID = value; } } string magzaAdi; public string MagzaAdi { get { return magzaAdi; } set { magzaAdi = value; } } public AdminMagzaGetir(int magzaID, string magzaAdi) { this.magzaID = magzaID; this.magzaAdi = magzaAdi; } }