为什么用以下语句取不出数据库新增行的标示号呢?大伙给看看
try
{
conn.Open();
SqlCommand comm = conn.CreateCommand();
SqlTransaction transaction = conn.BeginTransaction();
comm.Transaction = transaction;
comm.CommandText = "INSERT INTO Dept (DeptName, UpID, StopID) VALUES ('" + deptinfo.DeptName + "', " + deptinfo.UpID + ", " + deptinfo.StopID + ")";
comm.ExecuteNonQuery();
comm.CommandText = "SELECT @@IDENTITY From Dept";
int newDeptID = (int)comm.ExecuteScalar();
transaction.Commit();
conn.Close();
deptinfo.DeptID = newDeptID;
return deptinfo;
}
catch (Exception ex)
{
throw ex;
}