更新时间:2022-12-12 07:45:53
我如何通过新身份主键记录预览表?
如果只是显示数据两次,则无需在表格中插入重复数据,只需按照以下指南OleDbConnection con = new OleDbConnection();
con.ConnectionString = 此处的连接字符串;
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = 选择*来自dbo_NR_HMSWD50SQ_01_147;
OleDbDataAdapter adp = new OleDbDataAdapter(cmd.CommandText,con);
// 创建两个数据表
DataTable ds = new DataTable();
DataTable ds1 = new DataTable();
// 用相同数据填充
adp.Fill(ds);
adp.Fill(ds1);
// 将它们合并到一个数据表
ds.Merge(ds1);
// 并显示在gridview中
dataGridView1.DataSource = ds;
我希望这对你有帮助.......
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 :
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.
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 belowOleDbConnection 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........