473,473 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to show a message if your database query is empty

347 Contributor
I have the following form and I'm trying to add a error to the page that if the recordset = 0 then there is a message on the web page stating that there were no results. What's the best way to do that?

Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2. Imports System.Data
  3. Partial Class _Default
  4.     Inherits System.Web.UI.Page
  5.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  6.         TimeDateLabel.Text = String.Format("Today's date is {0:F}", DateTime.Now)
  7.     End Sub
  8.     Protected Sub whosoncallButton_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles whosoncallButton.Click
  9.         Dim dt As New DataTable
  10.         Dim da As New SqlDataAdapter
  11.         Dim cmd As New SqlCommand
  12.         Dim connectionString As String = "Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx"
  13.         Dim con As New SqlConnection(connectionString)
  14.         con.Open()
  15.         cmd.Connection = con
  16.         cmd.CommandType = CommandType.StoredProcedure
  17.         cmd.CommandText = "sp_getoncallresults"
  18.         cmd.Parameters.AddWithValue("@schedname", schednameTextBox.Text)
  19.         cmd.Parameters.AddWithValue("@sincedate", sincedateTextBox.Text)
  20.         Try
  21.             da.SelectCommand = cmd
  22.             da.Fill(dt)
  23.             GridView1.DataSource = dt
  24.             GridView1.DataBind()
  25.             con.Dispose()
  26.         Catch ex As Exception
  27.             Response.Write("Error:" & ex.ToString)
  28.         End Try
  29.     End Sub
  30.     Protected Sub clearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clearButton.Click
  31.         schednameTextBox.Text = ""
  32.         sincedateTextBox.Text = ""
  33.         GridView1.DataSource = Nothing
  34.         GridView1.DataBind()
  35.     End Sub
  36. End Class
  37.  
Apr 4 '11 #1
1 1564
dougancil
347 Contributor
I figured this out the line of code that I needed to add was:

If dt.Rows.Count = 0 Then
DataLabel.Text = ("There is no Data to Display")
Apr 4 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Brian | last post by:
Hi there I'm not so hot on JavaScript so not sure if this can be done. I have a PHP page that runs a MySQl query, while these queries are running I would like to show a message saying...
2
by: Gershon | last post by:
I have an ASP.NET/C# web application running against a SQL Server database using ADO.NET. Whenever there is a long-running database query, the web application hangs until the database query is...
3
by: Rob Venable | last post by:
Hi everyone, Can anyone see a problem with this code. I'm kinda new to asp.net and I'm having a problem populating a drop down list with a database query. The results of my query populate the list...
4
by: bnob | last post by:
In a Button clik event I have this code at the end of the event Response.Redirect("Page.aspx") But in this event I must show a message before redirect to the Page.aspx. I use to show Message...
4
by: krish | last post by:
Can anybody tell me how SQL query can be done using C
2
by: Mejmeyster | last post by:
Hi Everyone! I've been desperately trying to prepare a database query from Access to Excel. The problem is, when I ask MS Query to import data from more than one table, no data is importing, only...
5
by: Eglute | last post by:
Hello I want to show the results of database query in Visual basic. Do you know how to do this? I want to show the results in objects such as label or text box. Please help me. My code is: Dim db...
1
by: Eglute | last post by:
Hello I want to show the results of MS Access database query in Visual basic. Do you know how to do this? I want to show the results in objects such as label or text box. Please help me. My code is:...
1
by: jesmi | last post by:
my code is: U]employee.cfm <html> <head> <title>Employee List</title> </head> <body> <h1>Employee List</h1>
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.