Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello FRIENDS,

am working on asp.net , 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
1)RecordsTable
2)ArchievedTable

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.

Thanks.
Posted
Comments
Nandakishore G N 2-Feb-13 3:31am    
what have done till now? paste it.
Software Engineer 892 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 ?
Nandakishore G N 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..

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

SQL
declare @rec int
select @rec=count(*) from RecordsTable

if(@rec>200)
begin

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

end



Try u can get it done!!

Best of luck
 
Share this answer
 
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...

exa.....
//your insert coding is here

SQL
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);
cmd.ExecuteScaler();
cmd1.ExecuteScaler();

//then call gridbinding code here i.e refresh grid
BindDataToGrid();
}


something like this....hope it will help....
 
Share this answer
 
C#
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
 
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