throw new Exception(ex.Message + "(" + sqlcumle + ")"); çoklu silme yaparken fonksiyon.cs de oldu yardımcı olursanız sevinirim. İlk önce fonksiyon.cs sayfamı veriyorum ardından çoklu silme işlemini yaptığım haber.aspx sayfamı veriyorum:
Fonksiyon.cs
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 Fonksiyon
{
public Fonksiyon()
{
//
// TODO: Add constructor logic here
//
}
public SqlConnection baglan()
{
SqlConnection baglanti = new SqlConnection("Data Source=OGR112; Initial Catalog=HaberPortali;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 DataSet GetDataSet(string sql)
{
SqlConnection baglanti = this.baglan();
SqlDataAdapter adapter = new SqlDataAdapter(sql, baglanti);
DataSet ds = new DataSet();
try
{
adapter.Fill(ds);
}
catch (SqlException ex)
{
throw new Exception(ex.Message + "(" + sql + ")");
}
adapter.Dispose();
baglanti.Close();
baglanti.Dispose();
return ds;
}
public DataRow GetDataRow(String sql)
{
DataTable table = GetDataTable(sql);
if (table.Rows.Count == 0) return lisanssız;
return table.Rows[0];
}
public string GetDataCell(String sql)
{
DataTable table = GetDataTable(sql);
if (table.Rows.Count == 0) return lisanssız;
return table.Rows[0][0].ToString();
}
}
Haber.aspx.cs
lmadı:
using System;
using System.IO;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Haber : System.Web.UI.Page
{
public static string KategoriId = "";
string KategoriAdi = "";
string islem = "";
string HaberId = "";
Fonksiyon system = new Fonksiyon();
protected void Page_Load(object sender, EventArgs e)
{
KategoriId = Request.QueryString["KategoriId"];
islem = Request.QueryString["islem"];
HaberId = Request.QueryString["HaberId"];
if (islem == "sil")
{
string resimadi = system.GetDataCell("Select Resmi from Haber where HaberId=" + HaberId);
try
{
if (resimadi != "")
{
FileInfo fi150 = new FileInfo(Server.MapPath("../HaberResimleri/150/" + resimadi));
fi150.Delete();
FileInfo fi800 = new FileInfo(Server.MapPath("../HaberResimleri/800/" + resimadi));
fi800.Delete();
}
}
catch
{ }
system.cmd("Delete from Haber where HaberId=" + HaberId);
}
KategoriAdi = system.GetDataCell("Select KategoriAdi from Kategori where KategoriId=" + KategoriId);
Label lbl1 = (Label)Master.FindControl("lblSayfaBaslik");
lbl1.Text = KategoriAdi + "Haber";
HaberleriCek();
}
void HaberleriCek()
{
DataTable dtHaber = system.GetDataTable("Select * from Haber where HaberId=" + KategoriId);
rpHaber.DataSource = dtHaber;
rpHaber.DataBind();
}
protected void rpHaber_ItemCommand(object source, RepeaterCommandEventArgs e)
{
}
protected void btnSecilenleriSil_Click(object sender, EventArgs e)
{
string[] Secilenler = Request.Form["Haber"].ToString().Split(',');
for (int i = 0; i < Secilenler.Length; i++)
{
string silinecekId = Secilenler;
string resimadi = system.GetDataCell("Select Resmi from Haber where HaberId=" + silinecekId);
try
{
if (resimadi != "")
{
FileInfo fil150 = new FileInfo(Server.MapPath("../HaberResimleri/150/" + resimadi));
fil150.Delete();
FileInfo fil800 = new FileInfo(Server.MapPath("../HaberResimleri/800/" + resimadi));
fil800.Delete();
}
}
catch
{ }
system.cmd("Delete from Haber where HaberId=" + silinecekId);
}
Response.Redirect("Haber.aspx?KategoriId=" + KategoriId);
}
}
Fonksiyon.cs
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 Fonksiyon
{
public Fonksiyon()
{
//
// TODO: Add constructor logic here
//
}
public SqlConnection baglan()
{
SqlConnection baglanti = new SqlConnection("Data Source=OGR112; Initial Catalog=HaberPortali;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 DataSet GetDataSet(string sql)
{
SqlConnection baglanti = this.baglan();
SqlDataAdapter adapter = new SqlDataAdapter(sql, baglanti);
DataSet ds = new DataSet();
try
{
adapter.Fill(ds);
}
catch (SqlException ex)
{
throw new Exception(ex.Message + "(" + sql + ")");
}
adapter.Dispose();
baglanti.Close();
baglanti.Dispose();
return ds;
}
public DataRow GetDataRow(String sql)
{
DataTable table = GetDataTable(sql);
if (table.Rows.Count == 0) return lisanssız;
return table.Rows[0];
}
public string GetDataCell(String sql)
{
DataTable table = GetDataTable(sql);
if (table.Rows.Count == 0) return lisanssız;
return table.Rows[0][0].ToString();
}
}
Haber.aspx.cs
using System;
using System.IO;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Haber : System.Web.UI.Page
{
public static string KategoriId = "";
string KategoriAdi = "";
string islem = "";
string HaberId = "";
Fonksiyon system = new Fonksiyon();
protected void Page_Load(object sender, EventArgs e)
{
KategoriId = Request.QueryString["KategoriId"];
islem = Request.QueryString["islem"];
HaberId = Request.QueryString["HaberId"];
if (islem == "sil")
{
string resimadi = system.GetDataCell("Select Resmi from Haber where HaberId=" + HaberId);
try
{
if (resimadi != "")
{
FileInfo fi150 = new FileInfo(Server.MapPath("../HaberResimleri/150/" + resimadi));
fi150.Delete();
FileInfo fi800 = new FileInfo(Server.MapPath("../HaberResimleri/800/" + resimadi));
fi800.Delete();
}
}
catch
{ }
system.cmd("Delete from Haber where HaberId=" + HaberId);
}
KategoriAdi = system.GetDataCell("Select KategoriAdi from Kategori where KategoriId=" + KategoriId);
Label lbl1 = (Label)Master.FindControl("lblSayfaBaslik");
lbl1.Text = KategoriAdi + "Haber";
HaberleriCek();
}
void HaberleriCek()
{
DataTable dtHaber = system.GetDataTable("Select * from Haber where HaberId=" + KategoriId);
rpHaber.DataSource = dtHaber;
rpHaber.DataBind();
}
protected void rpHaber_ItemCommand(object source, RepeaterCommandEventArgs e)
{
}
protected void btnSecilenleriSil_Click(object sender, EventArgs e)
{
string[] Secilenler = Request.Form["Haber"].ToString().Split(',');
for (int i = 0; i < Secilenler.Length; i++)
{
string silinecekId = Secilenler;
string resimadi = system.GetDataCell("Select Resmi from Haber where HaberId=" + silinecekId);
try
{
if (resimadi != "")
{
FileInfo fil150 = new FileInfo(Server.MapPath("../HaberResimleri/150/" + resimadi));
fil150.Delete();
FileInfo fil800 = new FileInfo(Server.MapPath("../HaberResimleri/800/" + resimadi));
fil800.Delete();
}
}
catch
{ }
system.cmd("Delete from Haber where HaberId=" + silinecekId);
}
Response.Redirect("Haber.aspx?KategoriId=" + KategoriId);
}
}