如果没有数据则显示消息 [英] Show Message If No Data

查看:131
本文介绍了如果没有数据则显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多矩阵的报告(数据库SQL2005,对于报告,请使用Crystalreport,App-VB.net).如果报告上没有数据(所有矩阵均不返回数据),基本上我想做的是显示一条消息,例如在所选日期范围内没有历史记录".


I have a report(Database SQL2005, For report use Crystalreport, App-VB.net) with many matrices. Basically what I want to do is display a message such as "No History within Date Range Selected" if there is no data on the report (all of the matrices return no data).


Is there a way to determine if the report is returning no data and show a textbox message in that case?

推荐答案

Crystalreport中没有数据的3个潜在原因:
1)大写/小写不一致
要解决此问题,只需使用如下公式:UpperCase({Customer.Name}) = "BOB"

2)选择公式中出现不必要的空格
例如这样的公式:"Mr. " in {Customer.Title}将找不到任何匹配项,因为先生". (没有空格)在标题中.

3)日期格式不正确
例如:在sql server上,日期显示为:" MM/dd/yyyy ",而在本地计算机上则显示为:" yyyy/MM/dd "
更改sql服务器或本地计算机上的日期格式,或在sql问题中使用SET DATEFORMAT ymd;命令.

所以...首先检查公式!

如果上述解决方案没有帮助,请在显示crystalreport之前向数据库查询记录数,或对主体使用存储过程(推荐),如下所示:
There are 3 potential reasons for no data in crystalreport:
1) uppercase/lowercase inconsistency
To correct this problem just use formula like this: UpperCase({Customer.Name}) = "BOB"

2) unwanted spaces appear in selection formula
For example formula like this: "Mr. " in {Customer.Title} will not find any matches because of "Mr." (without of space) in the title.

3) uncorrect dates formats
For example: on the sql server dates are presented as: "MM/dd/yyyy", but on the local comupter: "yyyy/MM/dd"
Change the date format on your sql server or on the local computer or use SET DATEFORMAT ymd; command in your sql question.

So... first check the formulas!

If solution above is not helpful, ask your database for count of records before showing crystalreport or use stored procedure (recommended) with the body like this:
IF NOT EXISTS( Field1, Field2, Field3
               FROM [DatabaseName].[dbo].[TableName1]
               WHERE (Field4 BETWEEN @dFrom AND @dTo ))
BEGIN
     SELECT 'No History within Date Range Selected' AS [CommentField]
ELSE
     SELECT Field1, Field2, Field3
     FROM [DatabaseName].[dbo].[TableName1]
     WHERE (Field4 BETWEEN @dFrom AND @dTo)


这篇关于如果没有数据则显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆