GUI 的动态查询

发布于 2024-11-30 18:41:42 字数 299 浏览 1 评论 0原文

我的数据库将学生的信息存储在一个表中,并将他们的课程信息存储在其他表中。还有更多关联表。

现在我想创建一个如下所示的表单: 在此处输入图像描述

根据搜索条件,应执行查询。 可以选择多个条件。点击搜索按钮后,将显示各种元组。

让我感到困惑的是我应该如何继续查询部分......???

有人可以帮我吗? 顺便说一句,我使用 SQL 2008R2 和 Visual Studio 2010。

My Database stores the information of Students in a tables along with their course offerings in other tables. There are more associated tables.

Now I wanna create a form that looks like this : enter image description here

Depending on the search criterion, the Query shall be executed.
More than one criterions may be selected. After hitting the search button, the various tupples shall be displayed.

Whats teasing me is how should i proceed with the Query part....???

Can anyone please help me out?
b.t.w. I use SQL 2008R2 along with Visual Studio 2010.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温暖的光 2024-12-07 18:41:42

如果我明白你想要什么,那么你可以使用一个看起来像这样的存储过程。

create procedure GetIT
  @Name varchar(10) = null,
  @AdminNo varchar(10) = null,
  @TickNo varchar(10) = null,
  @Course varchar(10) = null,
  @AcaYear varchar(10) = null
as

select T.YourColumnList
from YourTable as T
where  
  (T.Name    = @Name    or @Name    is null) and
  (T.AdminNo = @AdminNo or @AdminNo is null) and
  (T.TickNo  = @TickNo  or @TickNo  is null) and
  (T.Course  = @Course  or @Course  is null) and
  (T.AcaYear = @AcaYear or @AcaYear is null)

根据选择的单选按钮,您将传递一个值或 null 作为参数。

T-SQL 中的动态搜索条件

If I understand what you want then you could use a stored procedure that looks something like this.

create procedure GetIT
  @Name varchar(10) = null,
  @AdminNo varchar(10) = null,
  @TickNo varchar(10) = null,
  @Course varchar(10) = null,
  @AcaYear varchar(10) = null
as

select T.YourColumnList
from YourTable as T
where  
  (T.Name    = @Name    or @Name    is null) and
  (T.AdminNo = @AdminNo or @AdminNo is null) and
  (T.TickNo  = @TickNo  or @TickNo  is null) and
  (T.Course  = @Course  or @Course  is null) and
  (T.AcaYear = @AcaYear or @AcaYear is null)

Depending on what radio buttons are selected you will pass a value or null as an argument.

Dynamic Search Conditions in T-SQL

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文