Buyrun
Kod: Kodu kopyalamak için üzerine çift tıklayın!
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Fonksiyon
/// </summary>
public class Metodlar
{
public Metodlar()
{
//
// TODO: Add constructor logic here
//
}
public SqlConnection baglan()
{
SqlConnection baglanti = new SqlConnection("Data Source=localhost;Initial Catalog=orhanbul;Integrated Security=True");
baglanti.Open();
return (baglanti);
}
public int cmd(string sqlcumle)
{
SqlConnection baglan = this.baglan();
SqlCommand sorgu = new SqlCommand(sqlcumle, baglan);
int sonuc = 0;
try
{
sonuc = sorgu.ExecuteNonQuery();
}
catch (SqlException ex)
{
throw new Exception(ex.Message + " (" + sqlcumle + ")");
}
sorgu.Dispose();
baglan.Close();
baglan.Dispose();
return (sonuc);
}
public DataTable GetDataTable(string sql)
{
SqlConnection baglanti = this.baglan();
SqlDataAdapter adapter = new SqlDataAdapter(sql, baglanti);
DataTable dt = new DataTable();
try
{
adapter.Fill(dt);
}
catch (SqlException ex)
{
throw new Exception(ex.Message + " (" + sql + ")");
}
adapter.Dispose();
baglanti.Close();
baglanti.Dispose();
return dt;
}
public DataRow GetDataRow(string sql)
{
DataTable table = GetDataTable(sql);
if (table.Rows.Count == 0) return null;
return table.Rows[0];
}
public string GetDataCell(string sql)
{
DataTable table = GetDataTable(sql);
if (table.Rows.Count == 0) return null;
return table.Rows[0][0].ToString();
}
}