How to store new records in new row of a datatable while retaining old values?
I have Desktop.aspx page with Gridview1 and Detailsview1 controls. My requirement is, if I click on a button in Detailsview1, that particular product name and it's price should be stored in a datatable which is bound to GridView2. So far, I am successful in accomplishing this. However, if I click on another product , a new row is inserted in Datatable, but it shows the first added record and not the recent one. I have stored datatable object in session. My source code is as follows:
Abhimanyu K VatsaPosted May 31, 2010, 7:40 AM
I think you have to use a SELECT procedure with INSERT procedure. INSERT will insert the data and SELECT will select the data from your database to your DetailsView1 control. You have to use the SELECT procedure in such a way that it only selects the last record. May be it will be as follows
SELECT * FROM table_name WEHRE id=IDENT_CURRENT('table_name')
//in above code IDENT_CURRENT will only work if you are using selection from one table not from multiple tables
SELECT * FROM table_names
WHERE ID = (SELECT MAX(ID) FROM table_names)
//above code will work for multiple tables also
I hope it will solve your problem.
If my answer helped you, then accept it.
Have a Good Programming