调整空字段的查询
在 Visual Studio 中,我正在做
SELECT calendar.info, …. ,
calendar.ino AS Expr1, doss.dosno
FROM calendar INNER JOIN
doss ON calendar.ino = doss.ino AND calendar.ino = doss.ino
WHERE (calendar.b_date >= @cboDateFrom) AND (calendar.b_date <= @cboDateTo) AND
calendar.aguv like @cboUitvoerder)
的工作,但是如果 @cboUitvoerder
为空怎么办,我怎样才能让它工作,它会删除最后一个 AND,以便它返回字段 aguv 的所有项目?
在我的代码中我有
private void btnRefresh_Click(object sender, EventArgs e)
{
string x = cboUitvoerder.SelectedItem.ToString();
this.calendarTableAdapter.Fill(this.togaDataSet.calendar, this.cboDateFrom.Value.Date, this.cboDateTo.Value.Date, x);
}`
In Visual studio I'm doing
SELECT calendar.info, …. ,
calendar.ino AS Expr1, doss.dosno
FROM calendar INNER JOIN
doss ON calendar.ino = doss.ino AND calendar.ino = doss.ino
WHERE (calendar.b_date >= @cboDateFrom) AND (calendar.b_date <= @cboDateTo) AND
calendar.aguv like @cboUitvoerder)
which works, but what if @cboUitvoerder
would be empty, how can I make it work that it would drop the last AND so it would return all items for field aguv ?
In my code I have
private void btnRefresh_Click(object sender, EventArgs e)
{
string x = cboUitvoerder.SelectedItem.ToString();
this.calendarTableAdapter.Fill(this.togaDataSet.calendar, this.cboDateFrom.Value.Date, this.cboDateTo.Value.Date, x);
}`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能做类似的事情吗:
Can you do something like:
我认为你可以使用 Rob 博士的解决方案,但如果你想将 null 作为 @cboUitvoerder 传递,你应该使用 DBNull.Value 而不是 c# null。
I think you can use the sloution from Dr Rob, but if you want to pass null as a @cboUitvoerder, you should use DBNull.Value instead c# null.