Displaying an error message when no records are returned

asp.net , access , search function Poole, United Kingdom
  • 11 years ago
    Hi all, I have added a search function on my website today using Microsoft Access, by the use of select statements and all works fine. However, I am unsure of how to display an error message when there isnt any records found. Does anyone have an idea of how to do this? Many Thanks. James
  • 11 years ago
    Hi all, I have added a search function on my website today using Microsoft Access, by the use of select statements and all works fine. However, I am unsure of how to display an error message when there isnt any records found. Does anyone have an idea of how to do this? Many Thanks. James
  • 11 years ago
    hi, Do you mean you dont know how to check that no results are returned? Si
  • 11 years ago
    Hi Si No sorry..I meant to say that on the page I have one textbox and one button. When you type in a valid query into the textbox it will redirect the user to a page listing all the possible matches for that query. But if you type something, which the database cannot find it comes up blank. So i was wandering if there was a way where I could have an error message saying that the results cannot be found. Thank you
  • 11 years ago
    Hiya, that is pretty much what i was asking, from what i understand this is what is happening. user enters a search term and hits search user is redirected to a page that shows results page searches the database but returns no records page just displays a blank result set if this is the case, then when you call the database, you should do a check to see if some records are returned. if not, then bounce them back to the search page with a message that no results could be returned. Si
  • 11 years ago
    Thank you for your reply Yes that is whats happening at the moment. I have tried to do a count but it comes up with a compilation error. I have tried various other things but I havent had no luck as of yet. I was wandering if you could help me with this. Many Thanks, James
  • 11 years ago
    ok, How are you returning the results? is it a dataset? if it is, then you can use if dsdata is nothing orelse if dsdata.tables.count <= 0 orelse dsdata.tables(0).rows.count <= 0 then ' no data returned else ' data returned end if If it is a datareader, then you can check the hasrows property. Si
  • 11 years ago
    Thank you..I was using a datalist to return the data. I changed the code to: If Datalist.Items.Count <= 0 Then Label1.Text = "No Matches Found - Please try again" Label1.Visible = "True" Else Label1.Visible = "False" Thank you so much for your help. James

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson