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"
| CustomerID | Date | Store | Amount | NoStub |
| 1 | 8/5/20113 | Nike | 5000 | 2 |
| 2 | 8/6/2013 | Adidas | 4000 | 2 |
| 3 | 8/7/2013 | Converse | 2000 | 1 |
Table "StubRange"
| RangeID | CustomerID | NoStub | StubStart | StubEnd |
| 1 | 1 | 2 | 0001 | 0002 |
| 2 | 2 | 2 | 0003 | 0004 |
| 3 | 3 | 1 | 0005 | 0005 |
Just Imagine the output and anyone can create me line of code to have this kind of output.
venkata kumarPosted Aug 8, 2013, 5:14 AM
use stored procedure in that you can do both insert and update