Click here to Skip to main content
16,018,949 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have one form named set borrow duration.


where i have one textbox,one update button..

Requirement of the system:
The system shall be able to add these durations to return book date. E.g. 1st june is issued date then the return date SHALL be issue date+14 days i.e. 15 June SHALL be returned date of book.

i have tried likes this::


private void buttonUpdate_Click(object sender, EventArgs e)
{
SqlConnection connect = new SqlConnection(str);
connect.Open();
{
string newdate = textBox_Borrow.Text;
string sqlquery = "UPDATE Burrow_Duration SET Days=@newdate";
SqlCommand cmd = new SqlCommand(sqlquery, connect);
cmd.Parameters.AddWithValue("@newdate", textBox_Borrow.Text);
cmd.ExecuteNonQuery();
this.Close();


while executing the above code if burrow duration days is 5 then when i type 10 in textbox, database gets update ie 10 comes in database..because i have insert update query.
but i want like if 5+14=19 (14)should be automatically be inserted...
10+14=24 (14) should be automatically be Inserted!!!

can any body help me out!!!<strike></strike>
Posted
Updated 5-Jul-11 15:18pm
v3

Use triggers...
Or use coding, read the the no. of days from the database first and then make changes to and then update the changed value in database.
I think, trigger is better solution.
 
Share this answer
 
Comments
Christian Graus 5-Jul-11 23:07pm    
How does a trigger help here ? It really doesn't. A trigger is for doing X when you do any sort of insert, update, or delete. In this case, he wants to change the value he's updating, which is best done in a proc. Otherwise, his trigger will fire if he does ANY sort of update, and it would rely on him setting a bad value, and the trigger fixing it ( which would be impossible, as he'd have overwritten the data he needed to fix it )
You need to do a few things.

First of all, you need to set the date for only the book in question, with a where clause. Second, you need to calculate the date you want. The best way to do this, is in a stored proc, where you pass in a date, and the proc calculates the value you want from the value there, plus the value you passed in. Otherwise, you need to ask the DB for the current value, and calculate it in code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900