Click here to Skip to main content
15,903,724 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi every one.

I have many records in my table, i need those and also need a copy of those records in that table.
I use linq, and i can use it for insert coz of identity problem. Is said this primary key already exists.
For example :
C#
var myRecords = from i in db.tMytable
Where i.name.Contains("A")
select i;


how can i these record to previews Table by new identity Primary key ?

Thanks in advance.
Posted

1 solution

how can i these record to previews Table by new identity Primary key ?


If it just about displaying the data twice then no need to insert duplicate data in your table simply follow the guidelines below


C#
OleDbConnection  con = new OleDbConnection ();
con.ConnectionString = "your connection string here";
con.Open();
OleDbCommand cmd=new OleDbCommand();
cmd.CommandText = "Select * from dbo_NR_HMSWD50SQ_01_147";
OleDbDataAdapter adp = new OleDbDataAdapter(cmd.CommandText , con);
            
//Create two datatables

DataTable ds = new DataTable();
DataTable  ds1 = new DataTable();
           
//Fill them with same data

 adp.Fill(ds);
adp.Fill(ds1);

//merge them to one datatable

ds.Merge(ds1);

//and display in your gridview

dataGridView1.DataSource = ds;



I hope this helps you........
 
Share this answer
 
v3
Comments
arminamini 15-Apr-13 2:55am    
Thanks, but i need to change 2 field of all records and insert them again.
how about it?
Raj Parashar 15-Apr-13 5:25am    
Then u can use another table with same fields and connect the tables using foreign Key that should work. And yes u can't have duplicate primary keys in any case.

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