Click here to Skip to main content
11,804,008 members (81,273 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server

am working on , c# , SqlServer 2005.

my requirement is., I have a database to insert the records through Gridview Footer.
Its works fine.

I have Two tables in SqlServer Database...ok

so, when user enters records from Gridview Footer. if the records reachs 200 records. Last old 50 Records must be automatically inserted into ArchievedTable.

Please can you help me.

Posted 1-Feb-13 20:04pm
Nandakishorerao at 2-Feb-13 3:31am
what have done till now? paste it.
Software Engineer 892 at 2-Feb-13 4:44am
Sir, it is inserting perfectly in records Table....if records table reachs 200 records.
the last 50 records must be automatically inserted into new table(ArchievedTable)

So, in record table it will have 150 records and in Archieved Table it will have 50 Records.

Please can u show me how to do this ?
Nandakishorerao at 2-Feb-13 5:07am
Yes...i can understand..if you paste the code we can surely help you in completing it.
Are you maintaining track of 200 records..?How are you doing it?..these are the questions pops out..therefore paste the code..
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Use a stored proc/trigger(run the horses of u r mind somewhat) for this some code you may use like

declare @rec int
select @rec=count(*) from RecordsTable
select top 50 * from RecordsTable --declare a table variable for this
--Now use a loop / MERGE command(probably N/A in SQL 2005) to sync the tables
--using insert query


Try u can get it done!!

Best of luck
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

if there any field like id....which is sequentially increasing....or any autoid field in table like1,2,3,4... then do following.....
1.On insert coding check row count
2.If row count is 200.
3.Execute to command one is to transfer record from one table to secound which is selected by order by id asc
4.Delete from first table
5.Refresh gridview...rebind to database...

//your insert coding is here
int RecordsCount = Gridview1.Rows.Count ;
if (RecordsCount == 200)
//execute folowing command
cmd=new SqlCommand("insert into ArchievedTable(col_a, col_b)
select top 50 col1, col2 from RecordsTable
order by id asc",con);
cmd1=new SqlCommand("DELETE FROM RecordsTable WHERE id IN (SELECT TOP 50 id FROM RecordsTable ORDER BY id asc)",con);
//then call gridbinding code here i.e refresh grid

something like this....hope it will help....
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

for (int i = 0; i < (GridView1.Rows.Count) - 50; i++)
           // save routine for Table that contains first 150 records
           BindWebControls.SetDataTarget(cn, "insert into put values('" + GridView1.Rows[i].Cells[0].Text + "')", 1, Label1);
       for ( int z =(GridView1.Rows.Count) - 50;  z < GridView1.Rows.Count; z++)
           // save routine for Table that contains last 50 records
           BindWebControls.SetDataTarget(cn, "insert into put1 values('" + GridView1.Rows[z].Cells[0].Text + "')", 1, Label1);

reply if it helped you

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

  Print Answers RSS
0 OriginalGriff 410
1 CPallini 310
2 Sergey Alexandrovich Kryukov 234
3 CHill60 230
4 Suvendu Shekhar Giri 200
0 OriginalGriff 3,140
1 Maciej Los 1,910
2 KrunalRohit 1,907
3 CPallini 1,845
4 Richard MacCutchan 1,187

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100