[英]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.