如何根据界面输入日期对数据库中日期进行相关信息查询

本文介绍了一种方法,当用户在前端界面输入日期后,如何构造SQL查询语句从NoticeTable中筛选匹配日期的通知信息。查询语句示例如下:Select * from NoticeTable Where noticeDate=’选定日期’。接着,文章展示了如何遍历数据库结果,将通知ID、管理员ID、通知标题、通知内容和通知日期等信息逐条读取并展示在界面上。这部分代码适用于前端分页绑定到GridView的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前端界面类似于下面这样
在这里插入图片描述
数据库结构如下,表名为NoticeTable
在这里插入图片描述
界面中的TextBox,id为SelectDateTextBox
选中日期后点击查看按钮输入的SQL查询语句如下:
string selectString = “Select * from NoticeTable Where noticeDate=’” +DateTime.Parse ( SelectDateTextBox.Text.Trim()) + “’”;

数据库读取每条信息到显示界面上:

string noticeid = string.Empty;
string adminid = string.Empty;
string noticetitle= string.Empty;
string noticetext = string.Empty;
DateTime noticedate=new DateTime();//日期初始化
while (reader.Read())
{
noticeid = reader[“noticeID”].ToString();
adminid = reader[“adminID”].ToString();
noticetitle = reade

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值