Click here to Skip to main content
15,914,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to move records to another table, if the table reaches 100 records
----------------------------------------------------------------------

Dear Frnds,

am working on asp.net c#, SqlServer 2005.

I have created a webapplication, In this webapplication i have webpage with gridview with footer textboxes to enter the records. If this gridview reaches 100 records, last 50 records must be moved to another table.

In database i have 2 tables TableA and TableB....if the TableA reaches 100 records last 50 records must move to TableB.

Please can you help me how to do this ?

Thanks in advance.
Posted

I have ask WHY. There needs to be a very good business reason to do this because if it is driven solely by the number of rows in your datagrid then you are building a nightmare not an application.
 
Share this answer
 
Comments
bbirajdar 28-Jul-13 5:04am    
:) :) :)
you can check count of records in tableA at the time of adding records. If that number is greater than or equal to 100 then get the records from tableA in desc form and get top 50. You can add them to a generic list<type of="" class="" to="" hold="" object="" tablea=""> and insert into tableB.

Then you can delete records from tableA.

Second way to do that is with the help of sql query. check these links for details.
http://blog.sqlauthority.com/2007/08/15/sql-server-insert-data-from-one-table-to-another-table-insert-into-select-select-into-table

http://blog.sqlauthority.com/2012/10/31/sql-server-copy-data-from-one-table-to-another-table-sql-in-sixty-seconds-031-video

Thanks,
Jagjot
 
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