Print Page | Close Window

Field in code?

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=8851
Printed Date: 28 March 2026 at 11:41pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Field in code?
Posted By: Boecky
Subject: Field in code?
Date Posted: 13 January 2004 at 11:07am

Anybody knows how I can check in my code how I can see if a db query is empty?

something like

If Databinder.Eval(Container.DataItem, "Test") Is DBNull.Value Then

....

End If<%# binder.Eval(Container.Item, "er_nl") %><%# binder.Eval(Container.Item, "Title_nl") %><%# binder.Eval(Container.Item, "Title_nl") %>




Replies:
Posted By: Mart
Date Posted: 13 January 2004 at 11:09am
You can create sub's and functions and use them normally inside a <%# ... %>
e.g. <%# MyFunction(Databinder.Eval(Container.DataItem, "Test")) %>

Public Function MyFunction(data As object) As String
return "the data is " & data
End Function


Posted By: MorningZ
Date Posted: 13 January 2004 at 12:28pm

another angle:

to avoid having to seperately check for NULL or "emtpy string", i typically make sure the data coming back from the base is at least a  string, a la:

SELECT IsNull( SomeColumn, '' ) As SomeColumn FROM SomeTable



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Mart
Date Posted: 13 January 2004 at 12:40pm
What will that return SomeColumn as? i.e. If its null does it return 0 and if not return 1?


Posted By: MorningZ
Date Posted: 13 January 2004 at 1:04pm
the sql statement i gave above will return "empty string" instead of NULL

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Boecky
Date Posted: 14 January 2004 at 6:43am

I wanna hide a panel when the query is empty, and the repeater is in this panel...



Posted By: Diep-Vriezer
Date Posted: 14 January 2004 at 11:16am

If QueryReturn = "emtry string" then

  yourPanel.visible = False

Else

  yourPanel.Visible = True

End If



-------------
Gone..


Posted By: MorningZ
Date Posted: 14 January 2004 at 11:20am

or in one line of code

yourPanel.Visible = (QueryReturn <> String.Empty)



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Boecky
Date Posted: 15 January 2004 at 3:48am
Ok, and as what i have to declare the QueryReturn?


Posted By: Boecky
Date Posted: 15 January 2004 at 5:24am
I also found this that also works:

If Not objReader.Read() Then

Panel1.Visible = False

End If



Posted By: Boecky
Date Posted: 15 January 2004 at 6:57am

hmm, this seems not to be a good solution, when there is 1 record, it will be hidden, also if there are more records, the first one is always not showed

Suggestions are welcome



Posted By: MorningZ
Date Posted: 15 January 2004 at 7:15am

This is the way i iterate through a DataReader

If objReader.HasRows() then
     While objReader.Read()
        'here we are iterating through the results
     End While
Else
     'No results
End if

Note that "HasRows()" is a .NET Framework 1.1 and above thing



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Boecky
Date Posted: 15 January 2004 at 10:24am

Thanks

I also found something else and this time it works also!

Repeater.DataBind()

Dim test As Integer

test = Repeater.Items.Count()

If (test = 0) Then

Panel1.Visible = False

Else

Panel1.Visible = True

End If



Posted By: Leeb65
Date Posted: 15 January 2004 at 10:28am

You could have just done a count query and then set the visability to true if greater than 0.

Lee



Posted By: MorningZ
Date Posted: 15 January 2004 at 2:05pm
Originally posted by Boecky Boecky wrote:

Thanks

I also found something else and this time it works also!

Repeater.DataBind()

Dim test As Integer

test = Repeater.Items.Count()

If (test = 0) Then

Panel1.Visible = False

Else

Panel1.Visible = True

End If

can all be done in one line of code

Panel1.Visible = ( Repeater.Items.Count() > 0 )



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Boecky
Date Posted: 19 January 2004 at 3:25pm
idd...much shorter



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net