Show "No Records Found" Message

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • RN1

    #1

    Show "No Records Found" Message

    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.DataSourc e = dSet.Tables("ET S").DefaultV iew
    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
  • Robert Dunlop

    #2
    Re: Show "No Records Found" Message

    "RN1" <rn5a@rediffmai l.comwrote in message
    news:4465159c-1500-446c-b78e-bd13bfdf1aeb@k3 7g2000hsf.googl egroups.com...
    ....
    dSet = New DataSet
    sqlDapter.Fill( dSet, "ETS")
    >
    dgETS.DataSourc e = dSet.Tables("ET S").DefaultV iew
    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 EmptyDataTempla te
    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.Vis ible = False
    dgETS.DataSourc e = dSet.Tables("ET S").DefaultV iew
    dgETS.DataBind( )
    else
    dgETS.Visible = False
    NoDataLabel.Vis ible = True
    end if


    --
    Robert Dunlop
    ----------------------


    Microsoft DirectX MVP 1998-2006


    Comment

    Working...