Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
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 1-Feb-13 21:04pm
Comments
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
good
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
 
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
  Permalink  
Rate this: bad
good
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...
 
exa.....
//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);
cmd.ExecuteScaler();
cmd1.ExecuteScaler();
 
//then call gridbinding code here i.e refresh grid
BindDataToGrid();
}
 
something like this....hope it will help....
  Permalink  
Rate this: bad
good
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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 319
2 CPallini 275
3 DamithSL 214
4 Maciej Los 185
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2014
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