ExecuteNoQuery的返回值是受影响的行数。对于 UPDATE、INSERT 和 DELETE 语句,返回值为该命令所影响的行数。对于所有其他类型的语句,返回值为 -1。如果发生回滚,返回值也为 -1。

解决方案 »

  1.   

    如果想返回记录数,请修改存储过程:
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS OFF 
    GOCREATE PROCEDURE dbo.GetBookByBookID
    @ID nchar(13),
    @Name nvarchar(80)=NULL OUTPUT,
    @ISBN nchar(13)=NULL OUTPUT,
    @SearchIndex nvarchar(20)=NULL OUTPUT,
    @LibraryID INT=NULL OUTPUT,
    @LocationID INT=NULL OUTPUT,
    @LocationDescribe nvarchar(20)=NULL OUTPUT,
    @Borrowed bit=NULL OUTPUT,
    @Lost bit=NULL OUTPUT,
    @Preengated bit=NULL OUTPUT,
    @AllowBorrow bit=NULL OUTPUT,
    @PressName nvarchar(60)=NULL OUTPUT
     ASselect count(*) as rowcount 
    from
    (SELECT 
    @Name=BookName,
    @ISBN=ISBN,
    @SearchIndex=SearchIndex,
    @LibraryID=LibraryID,
    @LocationID=Books.LocationID,
    @LocationDescribe=Locations.Describe,
    @Borrowed=Borrowed,
    @Lost=Lost,
    @Preengated=Preengated,
    @AllowBorrow=AllowBorrow,
    @PressName=PressName
    FROM 
    Books,Locations,Presses
    WHERE 
    Books.BookID=@ID AND
    Presses.PressID=Books.PressID AND
    Locations.LocationID=Books.LocationID) tmptableRETURN @@RowCount
    GO
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GO
    并在程序中使用这个语句:int nRowCount=(int)(commond.ExecuteScalar())
      

  2.   

    return @@XXXX,应该使用SqlCommand的存储过程执行方式,访问其返回参数可得。