简体   繁体   English

存储过程不返回任何数据asp.net sql server 2008 r2

[英]store procedure don't return any data asp.net sql server 2008 r2

I am coding a filter search functionality. 我正在编写过滤器搜索功能。 that is, user will search data on the basis of any record either datetime or name, number. 也就是说,用户将根据日期时间或名称,编号的任何记录来搜索数据。

here I am also returning the data from other table. 在这里,我还从其他表返回数据。 So i have implemented a inner join too. 所以我也实现了内部联接。 For this purpose my store procedure is as follows- 为此,我的存储过程如下:

ALTER PROC [dbo].[spFilterSearch]

@var1 VARCHAR(10),
@var2 VARCHAR(10),
@Printdate DATETIME,
@ToDate varchar(10),
@FromDate varchar(10)

AS BEGIN
    DECLARE @td DateTime SET @td=CONVERT(DATETIME,@ToDate,105)
    DECLARE @fd DateTime SET @fd= CONVERT(DATETIME,@FromDate,105)
    if(@Printdate <> NULL)
        BEGIN
            SELECT cVar1, cVar2, Printdate,
            bg.Fname AS Name
            FROM dbo.Table1 
            INNER JOIN dbo.jTable2 jt ON Table1.id = jt.id
            WHERE(cVar1 LIKE @var1+'%') AND
            (cVar2 LIKE @var2+'%') 
            AND (convert(datetime,Printdate,105)=@FPdate)
        END
    ELSE
        BEGIN
            SELECT cVar1, cVar2, Printdate,
            bg.Fname AS Name
            FROM dbo.Table1 
            INNER JOIN dbo.jTable2 jt ON Table1.id = jt.id
            WHERE(cVar1 LIKE @var1+'%') AND
            (cVar2 LIKE @var2+'%') 
            AND (convert(DATETIME,Printdate,105)>=@fd AND convert(DATETIME,Printdate,105)<=@td)

        END

END

(this procedure don't return any record) At front end I have coded like, to send null date I have created FPdate property as below public DateTime? FPdate { get; set; } (此过程不返回任何记录)在前端,我编写了类似的代码,要发送空日期,我在public DateTime? FPdate { get; set; }下面创建了FPdate property public DateTime? FPdate { get; set; } public DateTime? FPdate { get; set; }

and in this way I am using it in search event handler 并以此方式在search event handler使用它

if (txtPrintedOn.Text != "")
          {
              string[] dtt = txtPrintedOn.Text.Split(' ');
              objprop.FPdate = Convert.ToDateTime(dtt);
          }
          else
          {
              objprop.FPdate = null;
          }

and to send it in the form of parameter from the business layer I have wrote code like this- 并以参数的形式从业务层发送它,我已经编写了如下代码:

if (prop.FPdate.Equals(null))
        {
            cmd.Parameters.AddWithValue("@Printdate", SqlDbType.DateTime).Value = Convert.DBNull;
        }
        else
        {
            cmd.Parameters.Add("@Printdate", SqlDbType.DateTime).Value = prop.FPdate;
        }
if (prop.ToDate != null)
            cmd.Parameters.AddWithValue("@ToDate", SqlDbType.VarChar).Value = prop.ToDate;
        else cmd.Parameters.Add("@ToDate", SqlDbType.VarChar).Value = Convert.DBNull;

At the end Data set is being return empty. 最后,数据集将返回空。 I am banging my head against the wall since many hours but not getting any clue 几个小时以来,我的头一直撞在墙上,但没有任何头绪

where I am going wrong. 我要去哪里错了。 Please suggest a way to make it run. 请提出一种使其运行的方法。

Thanks 谢谢

Change SP to use following 更改SP以使用以下

if(@Printdate is not NULL)

Checkout these links - 检出这些链接-

Is there any difference between IS NULL and =NULL IS NULL和= NULL之间有什么区别吗

SQL is null and = null SQL为null和= null

Use this 用这个

cmd.Parameters.Add("@FPdate", SqlDbType.DateTime).Value = prop.FPdate.Value;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 asp.net中Windows Server 2008 R2上的PDF缩略图 - PDF Thumbnails on windows server 2008 R2 in asp.net 30秒后在ASP.NET上超时,在SQL Server 2008 R2上没有超时 - Timeout on ASP.NET after 30 seconds, on SQL server 2008 R2 no timeout 使用SQL Server 2008 R2在ASP.NET C#中创建Crystal Report - Creating Crystal Report in asp.net c# with SQL Server 2008 R2 部署使用Asp.Net,C#和Sql Server 2008 R2构建的Web应用程序 - Deploying an Web Application built using Asp.Net,C# and Sql Server 2008 R2 C#ASP.NET无法将联系页面上传到SQL Server 2008 R2 - C# ASP.NET trouble uploading contact page to SQL Server 2008 R2 使用SqlParameter实现C#ASP.NET和SQL Server 2008 R2的安全性 - Using SqlParameter for security with C# ASP.NET and SQL Server 2008 R2 具有SQL 2008 R2开发人员和SQL Express 2008 R2的ASP.Net C#ASPNETDB.mdb - ASP.Net C# ASPNETDB.mdb with SQL 2008 R2 Developers and SQL Express 2008 R2 C#SQL Server 2008 R2插入存储过程将不起作用 - C# sql server 2008 r2 insert stored procedure won't work SQL Server 2008 R2存储过程不起作用(visual c#) - SQL Server 2008 R2 stored procedure doesn't work (visual c#) 通过Process写入文件夹-ASP.NET和Windows Server 2008 R2 - Writing to folder through Process - ASP.NET and Windows Server 2008 R2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM