i have 2 tables in database. kategori->kategoriID,kategoriAdet.....makale-> makaleID,kategoriID.. i can delete a "makale" row from database using this code in makaleler.aspx

<a href="makaleler.aspx?makaleID=<%#Eval("makaleID")%>&islem=sil">
 <img alt="" class="auto-style6" src="../tema/sil.jpg" /></a>

and i have this code in makaleler.aspx.cs

SQLbaglanti baglan=new SQLbaglanti();
string makaleID = "";
string islem = "";
protected void Page_Load(object sender, EventArgs e)
{


    makaleID = Request.QueryString["makaleID"];
    islem = Request.QueryString["islem"];
    if (islem == "sil")
    {
        SqlCommand cmdmsil = new SqlCommand("delete from Makale where makaleID='"+makaleID+"'", baglan.baglan());
        cmdmsil.ExecuteNonQuery();

    }

What i want to do is; when i press delete image and delete a "makale" , i want "kategoriAdet" decrease 1 point from "kategori" table and update with the new number...For example i have "makale A" , and "makale A" relates with "kategoriID=1", and "kategoriID=1" has the number 5 in "kategoriAdet" field in "kategori" table , when i delete makale A , the number in the "kategoriAdet" that it belongs to the ID should be 4... i wrote a code ,but it doesnt subtract the number , it does nothing , can anyone guide me what to do? Here is my code:

SQLbaglanti baglan=new SQLbaglanti();
    string makaleID = "";
    string islem = "";
    protected void Page_Load(object sender, EventArgs e)
    {


        makaleID = Request.QueryString["makaleID"];
        islem = Request.QueryString["islem"];
        if (islem == "sil")
        {

            // makale silince kategori adeti eksiltme 
            SqlCommand cmdkadet = new SqlCommand("update Kategori set kategoriAdet=kategoriAdet-1 FROM Kategori INNER JOIN Makale ON  Kategori.kategoriID=Makale.kategoriID  where makaleID='"+ makaleID+"'", baglan.baglan());
            cmdkadet.ExecuteNonQuery();

        }

Related posts

Recent Viewed