从匹配多个条件的输入中显示网格视图
本文关键字:输入 显示 网格 视图 条件 | 更新日期: 2023-09-27 18:29:53
如何从数据库中显示与这两个条件之一匹配的GridView。我有3个输入文本框。第一个条件是基于第一个TextBox值进行显示,第二个条件是根据所有三个TextBox进行显示。我的条件是:
1.select * from CG_TPO_GOV_EventDetails where EventName='Event Name 1'
2.select * from CG_TPO_GOV_EventDetails where EventName='Event Name 1' and StartDate='2011-11-11' and EndDate='2012-11-11'
您需要编写SQL查询(我更喜欢存储过程),然后像这样处理情况,不要使用SELECT * from
,只使用您需要的任何列,
CREATE PROCEDURE SomeProcudereName
@EventName Nvacrchar(500),
@startDate DATETIME=NULL,
@EndDate DATETIME =NULL
AS
BEGIN
IF EXISTS(SELECT TOP 1 1 from CG_TPO_GOV_EventDetails where EventName=@EventName)
BEGIN
IF @startDate IS NULL AND @EndDate IS NULL
BEGIN
select yourColumns from CG_TPO_GOV_EventDetails where EventName=@EventName -- 1st condition
END
ELSE
BEGIN
select yourColumns from CG_TPO_GOV_EventDetails where EventName=@EventName and StartDate<@EndDate and EndDate >=@EndDate -- do for 2'nd COndition
END
END
ELSE
BEGIN
// No Events Found
END
END
对于日期之间的检查,你可以参考这个链接,它告诉非常清楚地选择日期之间的数据
然后使用此结果将文本框与数据集绑定