?
Solved

when datagrid returns no results

Posted on 2005-04-01
8
Medium Priority
?
250 Views
Last Modified: 2010-04-07
i know how to return the number of records in a datagrid using sql server, but i'm not sure with microsoft access.

i need to display a message if no records are returned.

here's the sql server code:

if( myDataSet.Tables(0).Rows.Count = 0 )
            response.write ("No results")
      else
            'Bind the DataSet to Datagrid
            dgSearchResults.DataSource = myDataSet
            dgSearchResults.DataBind()
      end if

how would i do this using access?

thanks, all.
0
Comment
Question by:vbnewbie01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 13686653
it's the same.

DataTables and DataSets are another layer and have nothing to do with whether the data source is Access or SQL Server or MySQL or even Oracle(heaven forbid!)


Dim visible As Boolean = (myDataSet.Tables(0).Rows.Count > 0)
dgSearchResults.Visible = visible
'use a label to hold the text that you want to display
'when no records are returned.
lblNoResults.Visible = Not visible


'even if the datatable has no rows
'binding it to the grid will clear any existing item rows
'this will clear off any item rows inside the grid

dgSearchResults.DataSource = myDataSet.Tables(0)
dgSearchResults.DataBind()
0
 
LVL 1

Author Comment

by:vbnewbie01
ID: 13686741
hi, b1xml2 ... the thing is, i'm not using a dataset.

here's the full procedure below:


sub DisplayShowGenreSearchResults(byVal intSelectedGenre as integer)
      

      dim strConnection As Oledb.OledbConnection = New Oledb.OledbConnection(ConfigurationSettings.Appsettings("myDB"))
      
      strConnection.open
      
      Dim strSQL as String = "SELECT tblShows.fldShowID, tblShows.fldShowTitle " _
      & "FROM tblShowGenres INNER JOIN (tblShows " _
      & "INNER JOIN tblShowsGenresLink " _
      & "ON tblShows.fldShowID = tblShowsGenresLink.fldShowID) " _
      & "ON tblShowGenres.fldShowGenreID = tblShowsGenresLink.fldShowGenreID " _
      & "WHERE (((tblShowGenres.fldShowGenreID)=" & intSelectedGenre & ")) " _
      & "ORDER BY tblShows.fldShowTitle ASC"
      


Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, strConnection)
      

dgShowSearchResults.dataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
dgShowSearchResults.DataBind()

   
end sub
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13686774
well then, you would have to change that behaviour:


Private Sub DisplayShowGenreSearchResults(ByVal intSelectedGenre As Integer)
      Dim con As New OleDbConnection(ConfigurationSettings.AppSettings("myDB"))
      Dim cmd As OleDbCommand = con.CreateCommand()
      Dim sql as String = "SELECT tblShows.fldShowID, tblShows.fldShowTitle " _
            & "FROM tblShowGenres INNER JOIN (tblShows " _
            & "INNER JOIN tblShowsGenresLink " _
            & "ON tblShows.fldShowID = tblShowsGenresLink.fldShowID) " _
            & "ON tblShowGenres.fldShowGenreID = tblShowsGenresLink.fldShowGenreID " _
            & "WHERE (((tblShowGenres.fldShowGenreID)=" & intSelectedGenre & ")) " _
            & "ORDER BY tblShows.fldShowTitle ASC"
      cmd.CommandText = sql
      Dim da As New OleDbDataAdapter(cmd)
      Dim ds As New DataSet()
      da.Fill(ds,"Genres")
      Dim dt As DataTable = ds.Tables("Genres")
      Dim visible As Boolean = (dt.Rows.Count > 0)
      dgSearchResults.Visible = visible
      'use a label to hold the text that you want to display
      'when no records are returned.
      lblNoResults.Visible = Not visible


      'even if the datatable has no rows
      'binding it to the grid will clear any existing item rows
      'this will clear off any item rows inside the grid

      dgSearchResults.DataSource = dt.DefaultView
      dgSearchResults.DataBind()

End Sub
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Accepted Solution

by:
zaghaghi earned 400 total points
ID: 13686828
after binding data to datagrid, use this code:

If dgsearchResults.Items.Count < 0 then
          dgSearchResult.Visible = false
          response.write("No result")
end if
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 13686830
sub DisplayShowGenreSearchResults(byVal intSelectedGenre as integer)
     

     dim strConnection As Oledb.OledbConnection = New Oledb.OledbConnection(ConfigurationSettings.Appsettings("myDB"))
     
     strConnection.open
     
     Dim strSQL as String = "SELECT tblShows.fldShowID, tblShows.fldShowTitle " _
     & "FROM tblShowGenres INNER JOIN (tblShows " _
     & "INNER JOIN tblShowsGenresLink " _
     & "ON tblShows.fldShowID = tblShowsGenresLink.fldShowID) " _
     & "ON tblShowGenres.fldShowGenreID = tblShowsGenresLink.fldShowGenreID " _
     & "WHERE (((tblShowGenres.fldShowGenreID)=" & intSelectedGenre & ")) " _
     & "ORDER BY tblShows.fldShowTitle ASC"
     


Dim myCommand As OleDbCommand = New OleDbCommand(strSQL, strConnection)
     

dgShowSearchResults.dataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
dgShowSearchResults.DataBind()

If dgsearchResults.Items.Count < 0 then
          dgSearchResult.Visible = false
          response.write("No result")
end if
   
end sub
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 13686835
Oooops, my previous code is incorrect
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 13686841
Ooops, my previous code must be correct ;)
0
 
LVL 1

Author Comment

by:vbnewbie01
ID: 13687011
thanks guys.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question