输入字符串格式不正确使用ObjectDataSource时出错

时间:2014-06-25 16:11:37

标签: c# asp.net sql-server-2008

我有一个存储过程可以在我的book表中搜索:

ALTER PROCEDURE dbo.book_serchbook
    @CategoryID int,@BookTitle nvarchar(100) ,
    @CategoryName nvarchar (100) ,
    @AuthorName nvarchar(100),
    @PublisherName nvarchar(100) 
AS
    SELECT DISTINCT 
       BookTable.BookID, BookTable.BookCover
    FROM          
       BookTable 
    INNER JOIN
       CategoryTable ON CategoryTable.CategoryID = BookTable.CategoryID
    INNER JOIN 
       PublisherTable ON PublisherTable.PublisherID = BookTable.PublisherID 
    LEFT OUTER JOIN
       BookAuthorTable 
    INNER JOIN 
       AuthorTable ON AuthorTable.AuthorID = BookAuthorTable.AuthorID 
       ON BookTable.BookID = BookAuthorTable.BookID
    WHERE     
      (BookTable.CategoryID = @CategoryID) OR
      (PublisherTable.PublisherName LIKE N'%' + @PublisherName + N'%') OR
      (BookTable.BookTitle LIKE N'%' + @BookTitle + N'%') OR
      (AuthorTable.AuthorFName + ' ' + AuthorTable.AuthorLName LIKE N'%' + @AuthorName + N'%') OR
      (CategoryTable.CategoryName LIKE N'%' + @CategoryName + N'%')

我想使用文本框进行搜索,并使用ObjectDataSourceGridView来显示结果:

<asp:ObjectDataSource ID="ObjectDataSource5" runat="server" 
     DataObjectTypeName="BookDataBaseComponent.BookDetails" 
     DeleteMethod="DeleteBook" InsertMethod="InsertBook" SelectMethod="SearchBook" 
     TypeName="BookDataBaseComponent.BookDB" UpdateMethod="UpdateBook">
     <DeleteParameters>
         <asp:Parameter Name="BookID" Type="Int32" />
     </DeleteParameters>
     <SelectParameters>
         <asp:Parameter DefaultValue="%" Name="CategoryID" Type="Int32" />
         <asp:ControlParameter ControlID="booktb" DefaultValue="%" Name="BookTitle" 
             PropertyName="Text" Type="String" />
         <asp:ControlParameter ControlID="DropDownList1" DefaultValue="%" 
             Name="CategoryName" PropertyName="SelectedValue" Type="String" />
         <asp:ControlParameter ControlID="alntb" DefaultValue="%" Name="AuthorName" 
             PropertyName="Text" Type="String" />
         <asp:ControlParameter ControlID="pubtb" DefaultValue="%" Name="PublisherName" 
             PropertyName="Text" Type="String" />
     </SelectParameters>
 </asp:ObjectDataSource>

当我运行项目时,收到一条错误消息:

  

输入字符串的格式不正确

1 个答案:

答案 0 :(得分:0)

<asp:Parameter DefaultValue="%" Name="CategoryID" Type="Int32" />如何有效?默认为带有% ??

的int32