Hi, I have code that increments values

 protected void IncrementOccur_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                //build object to insert occurrance
                Ad a = new Ad();

                a.AdID = Convert.ToInt32(ddlAddtype.SelectedValue);
                a.AdRef = Session["SessAppRef"].ToString();
                a.AdOcc = 1;

                try
                {
                    //insert advert object into db
                    AdManager.InsertAdOccRef(a);

                    //rebind the gridview
                    GridViewHistory.DataBind();

                    //reset the advert occurance label
                    lblAdOc.Text = CountAdRef();

                }
                catch (Exception ex)
                {

                }
            }
        }

This work grands and it increments. Now I need one for it to decrement. I'm not sure if the code is going to be the similar to what I already have? Obviously I would be inserting an Occurrance il be updating the occurance by -1. The way this works is Ive a database table that stores the information and everytime the increment button is clicked it saves it into the database. I have an SQL stored procedure that inserts the values into the database and instead of using sqldatasource we use objectdatasources. Any suggestios please

Recommended Answers

All 3 Replies

What value are you trying to decrement? Because as I far I undertand, you're not increment anything on your code, you are inserting a new record. Am I wrong?

Yea thats how the code is being incremented by updating the occurrance column in the database then pulling the data back. It's the way I was told to do it. So I was thinking for the decrementing I could update the occurrance column by using

 a.AdID = Convert.ToInt32(ddlAddtype.SelectedValue);9.                
 a.AdRef = Session["SessAppRef"].ToString();10.                
 a.AdOcc = -1;

changing it to -1 but I'm guessing this can't be done.

Was able to work this out myself, had to change my sql to an insert and update using an if statement

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.