Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 21st, 2005, 12:47 PM
Registered User
 
Join Date: Jan 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help checking for empty dataset

I have an Access database with items from a collection stored in it. Each item is in one of four catagories and the datagrid shows the items in a specific catagory based on a drop down list selection. Sometimes there won't be anything in a specific catagory like "For Sale" and I don't want to show a datagrid header with nothing in the datagrid (this is what my page is doing now). I am coding everything by hand; I don't use VS.NET.

Here is my function which is part of a namespace that I have compiled:

Code:
Public Function GetBalisongList(strStatus as string, strSort as string) as Dataset
    If strStatus = "complete" Then
        strSQL = "SELECT BalisongID, make, model, status FROM balisong ORDER BY " & strSort
    Else
        strSQL = "SELECT BalisongID, make, model, status FROM balisong WHERE status = '" & strStatus & "' ORDER BY " & strSort
    End If
    Dim objConnection as New OLEDBConnection(m_DSN)
    Dim objDataAdapter as New OLEDBDataAdapter(strSQL, objConnection)
    Dim BalisongList as new Dataset()
    objDataAdapter.Fill(BalisongList)
    Return BalisongList
End Function
Here is the sub that handles the drop down list in my code behind page:

Code:
Public Sub balisongfilter(sender as object, e as eventargs)
    ViewState("status") = ddl_balisong.SelectedItem.Value
    If ViewState("status") = "description" Or ViewState("status") = "" Then
        lblinstructions.visible = true
        dgBalisongList.visible = false
        rptBalisongDetails.visible = false
    Else
        strSort = "make, model"
        Dim BalisongStatusList as new Balisong(strconnect)
        dgBalisongList.DataSource = BalisongStatusList.GetBalisongList(ViewState("status"), strSort)
        dgBalisongList.DataBind()
        lblinstructions.visible = false
        dgbalisonglist.visible = true
        rptBalisongDetails.visible = false
    End If
End Sub
I am trying to display an asp:label saying something like, "I do not currently have any balisongs for sale." instead of an empty datagrid. Thank you in advance for any help you can provide.

 
Old January 21st, 2005, 02:31 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I think what you want is to test if the DataTable in the DataSet is empty:

DataSet.Tables(0).Rows.Count = 0

Or you could test the grid after it's bound:

DataGrid.Items.Count = 0

-Peter
 
Old January 21st, 2005, 11:11 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

if (ds == null) --- ds == dataset object


Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old January 24th, 2005, 03:46 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by Vadivel
 if (ds == null)
and its VB.NET equivalent code is,
Code:
if(ds Is Nothing)...
End If
(ds=Nothing is incorrect but in C# ds==null is correct!?)

_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old January 24th, 2005, 04:04 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

I think for comparing two objects and values,
Code:
//C#
if(Obj1==Obj2)
if(Value1==Value2)
'VB.NET
if(<s>Obj1=Obj2</s>)'incorrect
if(Obj1 Is Obj2)
if(Value1=Value2)
_____________________________
Mehdi.
software engineering student.
Looking for a good job for summer 2005.
 
Old March 28th, 2005, 05:00 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
if (ds == null || ds.Tables[0].Rows.Count == 0){}
if ds is null,there will be no check for the next condition so there would be no null reference exception.

_____________
Mehdi.
software student.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking to see if a label's text is empty mh JSP Basics 2 October 26th, 2005 11:05 AM
Checking to see if a label's text is empty mh ASP.NET 2.0 Basics 2 October 26th, 2005 10:38 AM
Checking for empty string richw32001 General .NET 1 August 8th, 2004 01:37 PM
checking for empty recordsets ! spraveens Classic ASP Databases 0 September 9th, 2003 10:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.