Results 1 to 12 of 12

Thread: IsEmpty with a dataset?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    10

    IsEmpty with a dataset?

    Hi,

    I am trying to test whether a table in a dataset is empty or not using an IF statement. ie has the SQL query retrieved any results or not. the table is called myLinks as below:

    <%# IF myLinks.IsEmpty() THEN %>
    <asp:Repeater id="myLinks" runat="server">

    ...

    ...

    </asp:Repeater>


    <% End If %>

    Is there such a thing as IsEmpty with these if not how do I perform such a test?


    I appreciate any help I can get, thanks,

    beNcooKe
    Attached Files Attached Files

  2. #2
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim woof As DataSet
    3.         'do stuff to dataset
    4.         If woof.Tables.Count = 0 Then
    5.             MessageBox.Show("No tables found in dataset")
    6.         Else
    7.             If woof.Tables.Item(0).Rows.Count = 0 Then
    8.                 MessageBox.Show("No rows found in 1st table")
    9.             Else
    10.                 MessageBox.Show("Rows were found...Boooooooooo")
    11.  
    12.             End If
    13.         End If
    14.     End Sub
    Hope that helps.

    Woof

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    10
    Ive tried a few combinations including

    <%# IF objDataSet.Tables.Item(1).Rows.Count <> 0 THEN %>

    but im afraid i just get the following error:

    "BC30201: Expression expected"

    Any other ideas??

    cheers,

    beN

  4. #4

  5. #5
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    You could always do:
    VB Code:
    1. Public Class MyDataSet
    2.     Inherits System.Data.DataSet
    3.  
    4.     Public Function IsTableEmpty(ByVal Index As Integer) As Boolean
    5.         Return (MyBase.Tables.Item(Index).Rows.Count = 0)
    6.     End Function
    7. End Class
    Then you can do:
    VB Code:
    1. Dim Woof As MyDataSet
    2.    'code to deal with woof
    3.   If Woof.IsTableEmpty(0) Then
    4.  
    5.   End If
    Although for one function I feel this may be overkill.

    Woka

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    10
    i have another table already in the dataset called "myResults" which is added first. I treid different index numbers and even putting the table name eg ("myLinks") in the parenthesese like when you refer to column names.

    all gave me the same error message as mentioned above,

    beN

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Why on earth are you placing all that scripting code into the web page? .NET should handle all this in it's class...

    Why not have that code in the ASP.NET Page_Load event and not some VBScript code or whatever it is.

    Woka

  8. #8
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    Woka's right (as usual). Are you not using VS.net. In line code is a bit of a nightmare.

    Woof

    Parksie

  9. #9

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    10
    i have another table already in the dataset called "myResults" which is added first. I treid different index numbers and even putting the table name eg ("myLinks") in the parenthesese like when you refer to column names.

    all gave me the same error message as mentioned above,

    beN

  10. #10

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    10
    well im still in development at the moment, at a later date all the code will be put into a seperate file and where possible things procedureised more and more.

    The essence of what im trying to do is there, this IsEmpty thing is getting a bit boggling though

    beN

  11. #11
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    The thing is that that error doesn't look like a .NET error
    I have not seen that before.
    You arn't using VS so it's a little hard for us to figure out what is wrong.
    I don't think it's to do with the .NET coding, more to do with you <&*% blah blah stuff...dunno what it's called.

    Woka

    venerable bede: I am right as usual??? 99% of the time I talk crap and am wrong

  12. #12

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    10
    the tags <%# ... %> are needed to create selective page content depending on user selections, page variables and the contents of SQL results.

    The page will be part of a much larger corporate site.

    Any further pointers?

    cheers

    beN
    Last edited by bencooke; Oct 12th, 2004 at 08:50 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width