具体来说就是: SqlConnection Conn = new SqlConnection(.......); string sql = "insert into 表 (字段) values ('值');select SCOPE_IDENTITY()"; SqlCommand Comm = new SqlCommand(sql, Conn); Conn.Open(); int id = Convert.ToInt32(myComm.ExecuteScalar());//这就是你要的值
Insert Into mytable values ('',) Select SCOPE_IDENTITY() --后面加一句会自动查询出刚才插入的自增id
select SCOPE_IDENTITY()
SqlConnection Conn = new SqlConnection(.......);
string sql = "insert into 表 (字段) values ('值');select SCOPE_IDENTITY()";
SqlCommand Comm = new SqlCommand(sql, Conn);
Conn.Open();
int id = Convert.ToInt32(myComm.ExecuteScalar());//这就是你要的值
Insert Into mytable values ('',)
Select SCOPE_IDENTITY() --后面加一句会自动查询出刚才插入的自增id