select @@identity from table

解决方案 »

  1.   

    是这样吗select @@identity as 'id' from table
      

  2.   

    @@identity是sql内的系统变量,保存最新产生的ID号,
    最好把插入记录写成存储过程,返回ID号
      

  3.   

    select id=@@identity
    不用加上"from table"
      

  4.   

    string sql="insert into table(column1,column2) values(value1,value2)";
    sqlcommand.commandtext=sql;
    sqlcommand.ExecuteNonQuery ();
    sql="select @@identity from table";
    sqlcommand.commandtext=sql;
    SqlDataReader myreader=sqlcommand.ExecuteReader ();
    if(myreader.read())
    {
    //
    }
      

  5.   

    试试这个,虽然不太好,不过也顶着用
    select MAX(id) from table