如何从codeBehind获取插入行的ID? [英] How to get Id of inserted row from codeBehind?..
本文介绍了如何从codeBehind获取插入行的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在从codebehind插入db表中.如何从codebehind插入最后一个原始的ID?...
谢谢
Amit
Hey everyone,
I am inserting into a db table from codebehind.How can i get the ID of this last raw inserted from codebehind?...
Thanks
Amit
推荐答案
该表将具有两列,分别称为ID和Name
ID是自动生成器
然后使用以下命令获取最后插入的记录ID
插入表格(``阿伦'');
select scope_identity();
The table will have two column called ID and Name
ID is auto generator
then use the below command for getting the last inserted record id
insert into tables(''Arun'');
select scope_identity();
Sqlcommand cmd = new SqlCommand(插入到dep(date)values(" 10/11/2010); select scope_identity();",con );
字符串serviceID
= cmd.ExecuteScalar();
Label.Text = serviceID;
Sqlcommand cmd=new SqlCommand("insert into dep(date)values (''10/11/2010'');select scope_identity();",con);
string serviceID
= cmd.ExecuteScalar();
Label.Text=serviceID ;
如果使用数据访问应用程序块,可能会更容易.
http://www.codeproject.com/KB/architecture/MS-EntLib- DataAccess1.aspx?msg = 3168720 [ ^ ]
It could be easier if you use Data Access Application Block.
http://www.codeproject.com/KB/architecture/MS-EntLib-DataAccess1.aspx?msg=3168720 [^]
这篇关于如何从codeBehind获取插入行的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文