StringBuilder strSql=new StringBuilder();
strSql.Append("insert into NicheInfo(");
strSql.Append("NicheTitle,NicheKey,Fatime)");
strSql.Append(" values (");
strSql.Append("@NicheTitle,@NicheKey,@Fatime)");
strSql.Append(";select @@IDENTITY");这张NicheInfo表中有4列 其中三列为NicheTitle,NicheKey,Fatime,还有一列为主键id列请问最后一句strSql.Append(";select @@IDENTITY") 在一个sql语句后加一个分号,再加
select @@IDENTITY 有何用意 什么意思 从没见过这样的

解决方案 »

  1.   

    主键ID列应该是自增的,所以不需要显式插入,插入数据后,最后一句查出ID
      

  2.   

    @@identity是表示的是最近一次向具有identity属性(即自增列)的表插入数据时对应的自增列的值,是系统定义的全局变量。一般系统定义的全局变量都是以@@开头,用户自定义变量以@开头。比如有个表A,它的自增列是id,当向A表插入一行数据后,如果插入数据后自增列的值自动增加至101,则通过select @@identity得到的值就是101。使用@@identity的前提是在进行insert操作后,执行select @@identity的时候连接没有关闭,否则得到的将是NULL值。
      

  3.   

    这个程序到这结束了么?如果单单执行insert into NicheInfo(NicheTitle,NicheKey,Fatime)values (@NicheTitle,@NicheKey,@Fatime);select @@IDENTITY肯定是有问题的。估计程序后面应该还有strSql.Append。
      

  4.   

    StringBuilder strSql=new StringBuilder();
    strSql.Append("insert into NicheInfo(");
    strSql.Append("NicheTitle,NicheKey,Fatime)");
    strSql.Append(" values (");
    strSql.Append("@NicheTitle,@NicheKey,@Fatime)");
    strSql.Append(";select @@IDENTITY");--其它select @@IDENTITY 返回主键自增列的最大值