2013-08-26 197 views
-1

我开发了一个搜索页面,其中包含用于输入数字和按钮的文本框控件,以在GridView中显示相应的结果。该页面在存储过程中起作用。当我手动输入数字时,sql查询通过SQL Server管理器运行时返回预期的结果,但在我的存储过程中使用时,我得到零结果。存储过程返回零结果

这是按钮事件处理程序后面的代码:

Dim ds As New DataSet() 

     Using connection As New SqlConnection(ConfigurationManager.ConnectionStrings("ShipperNotificationConnectionString1").ToString()) 
      Using command As New SqlCommand() 
       command.CommandType = CommandType.StoredProcedure 
       command.CommandText = "getPON" 
       command.Connection = connection 

       command.Parameters.AddWithValue("@PON", txtPON.Text) 

       connection.Open() 
       Dim a As New SqlDataAdapter(command) 
       a.Fill(ds) 
      End Using 
     End Using 

     gvPON.DataSource = ds 
     gvPON.DataBind() 

...以下是存储过程:

ALTER PROCEDURE [dbo].[getPON] 
(
    @PON varchar 
) 
AS 
BEGIN 
    SELECT  SupplierCompany.company_name, SupplierCompany.Address1, SupplierCompany.Address2, SupplierCompany.City, SupplierCompany.State, 
         SupplierCompany.Zip, Shipment_Po.PONumber, Shipment.TotalWeight, Shipment.NoOfPallets, Shipment.PalletIdentical 
FROM   SupplierCompany INNER JOIN 
         Shipment ON SupplierCompany.Company_guid = Shipment.Company_Guid INNER JOIN 
         Shipment_Po ON Shipment.Shipment_Guid = Shipment_Po.Shipment_guid 
      WHERE Shipment_Po.PONumber = '''+ @PON +''' 
END 

......可能有人请提供一些方向?

+0

'Shipment_Po.PONumber = @ PON' – bummi

回答

0

问题是存储过程。表达:

  WHERE Shipment_Po.PONumber = '''+ @PON +''' 

不是做你的想法。它做了以下比较:

  WHERE Shipment_Po.PONumber = '[email protected]+' 

或类似的东西。换句话说,您正在将动态SQL表达式与常规SQL混合使用。尝试这样做:

  WHERE Shipment_Po.PONumber = @PON 

如果您担心投向右类型:

  WHERE Shipment_Po.PONumber = (case when isnumeric(@PON) = 1 then cast(@PON as int) end) 
+0

两项建议的工作,谢谢! – user1724708