469,574 Members | 1,662 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,574 developers. It's quick & easy.

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 3585
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by amywolfie | last post: by
9 posts views Thread by Martin Eyles | last post: by
15 posts views Thread by Joachim | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.