473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Show "No Records Found" Message

RN1
Sub Page_Load(........)
If Not Page.IsPostBack Then
Call LoadData()
End If
End Sub

Sub LoadData()
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter

sqlConn = New SqlConnection("............")
sqlDapter = New SqlDataAdapter("SELECT * FROM ETS", sqlConn)

dSet = New DataSet
sqlDapter.Fill(dSet, "ETS")

dgETS.DataSource = dSet.Tables("ETS").DefaultView
dgETS.DataBind()
End Sub
----------------------------------

Suppose the SQL SELECT query doesn't output any records i.e. the
database table is empty. How do I show a "No Records Found" message in
a Label to the user?

Thanks,

Ron
Oct 21 '08 #1
1 3736
"RN1" <rn**@rediffmail.comwrote in message
news:44**********************************@k37g2000 hsf.googlegroups.com...
....
dSet = New DataSet
sqlDapter.Fill(dSet, "ETS")

dgETS.DataSource = dSet.Tables("ETS").DefaultView
dgETS.DataBind()
End Sub
----------------------------------

Suppose the SQL SELECT query doesn't output any records i.e. the
database table is empty. How do I show a "No Records Found" message in
a Label to the user?
If you are using ASP.NET 2.0, you could update the control from a DataGrid
(which I assume you are using based on the variable name dgETS) to a
GridView control. Then you could use the EmptyDataText or EmptyDataTemplate
properties to specify a message string or template to display when the
dataset is empty.

An alternative would be to test the return value from the call to Fill,
which returns the number of rows retrieved. You could then use this to
determine whether the data grid is displayed, or if instead a label on the
page is shown:

if sqlDapter.Fill(dSet, "ETS") = 0 then
dgETS.Visible = True
NoDataLabel.Visible = False
dgETS.DataSource = dSet.Tables("ETS").DefaultView
dgETS.DataBind()
else
dgETS.Visible = False
NoDataLabel.Visible = True
end if
--
Robert Dunlop
----------------------
http://www.directxzone.org
http://rdunlop.spaces.live.com
Microsoft DirectX MVP 1998-2006
Oct 21 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: amywolfie | last post by:
I would like to place a Find button on a form which uses the built-in Access Find facility. If no records are found, I would like to display a custom "no records found - plesae try again" message...
4
by: amywolfie | last post by:
I would like to put code behind a Find button on a form which: 1) Performs a find based on a field on the form 2) If NO RECORDS ARE FOUND, then displays a custom "No Records Found" message box. ...
9
by: Martin Eyles | last post by:
Hi, I have set up an asp.net website on another PC in order to test it. The site was fine on my PC, but on the new PC all the pages give the error "The Page Cannot Be Found". Some legacy pages...
15
by: Joachim | last post by:
Hi, Als a beginner, I am looking for a way to show records My code is Private sub Connection( Dim odbconn_Pro As OleDbConnectio Dim odbcomm_Pro As OleDbComman Dim odbdare_Pro As...
1
by: Kim | last post by:
How can I display "No data found" in the repeater if there are no records found after selecting an item from a dropdown list. Another question is: Can repeater perform paging as in datagrid if...
1
by: scottmachado | last post by:
I am currently running a marco that run a query and emails the results as an attachment in excel format. If the query has no records, I would like to email "no records found" in the first cell in...
0
by: sherifffruitfly | last post by:
Hi, I'm deleting a bunch of records from my DB, and they actually DO get deleted (as I verify by looking afterwards). But then I get the exception in the subject line. Isn't it weird that all of...
11
by: CrostonScottish | last post by:
Can anybody help? I have this code i have put together so that when i select values for my combo boxes which are linked to values in lookup tables, it opens my "frmriskass" with only the...
2
by: dissectcode2 | last post by:
Hi - I know almost nothing about Perl but do program in other languages. I am looking at Perl that I have to modify slightly by printing a "file not found" message if a file is missing from the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.