使用强类型的DataSet可以方便的操作数据库:有时候我们会对表的ID设置为自动增长,并且需要在插入数据后获取新插入数据的ID,按以下方法即可达到目的: 一.     首先建立一个表,id为自动增加,设置为主键 二.     建立DataSet,添加TableAdapter 1.  选择向导,"使用SQL语句" 2.  点"高级选项",在弹出的对话框中勾选"刷新数据表" 3.  填入SQL查询语句 4.  下一步,选择"创建方法以将更新…
Mybatis获取自动增长Id MyBatis成功插入后获取自动增长的id 1.向xxMapping.xml配置中加上两个配置. <insert id="insertUser" useGeneratedKeys="true" keyProperty="id" parameterType="UserEntity"> INSERT INTO USER VALUES(null,#{userName},#{password…
public Integer insertObjects(final Goods entity) { // 定义sql语句        final String sql1 = "insert into goods(name,price,cid)values(?,?,?)"; /*         * int num = jdbcTemplate.update(sql1, new Object[] { entity.getName(),         * entity.getPric…
<?php $mysqli=@new mysqli("localhost", "root", "123456", "xsphpdb"); if(mysqli_connect_errno()){ echo "连接数据库失败:".mysqli_connect_error(); $mysqli=null; exit; } //select语句(结果集), 非select语句,会影响行数 $sql="…
VB.NET中使用Linq TO SQL添加数据后获得自增长列ID: Dim tempOrdre As New Order With { .CustomerID = cmbCustomerName.SelectedValue.ToString, .ProductID = cmbProductSpec.SelectedValue.ToString, .ProductNumber = txtProductNumber.Text.Trim, .BatchNO = txtBatchNO.Text.Tri…
假设表结构如下: CREATE TABLE TestTable ( id int identity, CreatedDate datetime ) SQL2005获得新增行的自动增长列的语句如下: insert into TestTable (CreatedDate)  output  inserted.id  values (getdate()) output 是sql server2005的新特性,可以从数据修改语句中返回输出,可以看作是“返回结果的DML” 2005之后 Insert,De…
用下面的语句肯定是行不通的,语句不支持 truncate table t_Records 方法:1.删除表数据 2.重置自动增长列 where name='t_Records' /*name :是表名*/ SQLite Expert软件网址:  http://www.sqliteexpert.com/…
在项目开发中,遇到一个问题,先添加一条记录然后想立刻获取这条记录的ID值,ID由SQLServer自动增长的,如果先插入再查询的话,需要另外执行一条查询ID的SQL语句,因此有了下面的方法: 1.使用SQLServer自带的identity功能: sql="insert into dbo.OBDCustomer values(?,?,?,?,?,?) select @@IDENTITY as ID"; 2.要执行这条语句,应该是查询,而不是更新,因此需要调用executeQuery()…
  ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 insert into Tb_People(uname,era,amount) values( '兆周','老年','10000')   select @@identity   --当运行完插入语句后,执行select   @@identity就可得到自动生成的id   --如果是sql server 最好用select SCOPE_IDENTITY() a…
使用mybatis向数据库中插入一条记录,如何获取成功插入记录的自增长id呢? 需要向xml配置中加上一下两个配置: <insert id="add" useGeneratedKeys="true" keyProperty="id" parameterType="com.work.model.ScheduleInfoTable"> insert into scheduleInfo(title,content,tim…