1
Answer

creating a method that inserting and updating at a time

Ask a question
ASdf ghjk

ASdf ghjk

11y
886
1
I just want to have a method that when you insert a record there's a table will update. Here is my code in my inserting record.

 private void InsertReceipt()
        {   
            decimal Stub;
            Stub = Math.Floor(decimal.Parse(txtAmount.Text) / 2000);
           
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = cn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "INSERT INTO Ticket(CustomerID, Date, Store, Amount, NoStub)" +
                        "VALUES (@CustomerID, @Date, @Store, @Amount, @NoStub) ";
            cmd.Parameters.AddWithValue("@CustomerID", txtCustomerID.Text);
                cmd.Parameters.AddWithValue("@Date", dtpDate.Value.Date.ToString());
            cmd.Parameters.AddWithValue("@Store", txtStore.Text);
            decimal amount = decimal.Parse(txtAmount.Text);
            cmd.Parameters.AddWithValue("@Amount", amount);
            cmd.Parameters.Add("@NoStub", SqlDbType.Decimal).Value = Stub;

            cmd.ExecuteNonQuery();            
        }

For example this data is added to the Table "Ticket", I want to have an output that would display to the Table "StubRange".

Table "Ticket"

CustomerIDDateStoreAmountNoStub
18/5/20113Nike50002
28/6/2013Adidas40002
38/7/2013Converse20001

Table "StubRange"

RangeIDCustomerIDNoStubStubStartStubEnd
11200010002
2220003 0004
33100050005


Just Imagine the output and anyone can create me line of code to have this kind of output.


Answers (1)