Solved

Why is optional char argument nothing, not empty string?

Posted on 2010-09-15
2
359 Views
Last Modified: 2013-11-07
I have the following vb.net routine in an asp.net page:
   Private Sub GetGridData( _
         Optional ByVal sStatus As String = "New", _
         Optional ByVal sBookmark As Char = "")

      Dim sSQL As String
      Dim sWHERE As String = "WHERE 1=1 "

      If sStatus <> "Enabled" Then
         sBookmark = ""
         dlBookmark.Visible = False
      Else
         ' Do something else
         sBookMark = "x"
      End If

      sSQL = "SELECT * FROM MySQLView " & sWHERE

      If sBookmark <> "" Then
         ' FixSQL wraps single quotes around a string
         sSQL &= "AND Left(Name, 1) = " & FixSQL(sBookmark) & " "
      End If

      sSQL &= "ORDER BY Status, Name"

      Dim dr As SqlDataReader = dbHelper.OpenDataReader(sSQL)

      MyDataGrid.DataSource = dr
      MyDataGrid.DataBind()
   End Sub

Open in new window


This code no longer works when called as follows:
   GetGridData()

Open in new window


sBookmark has a value of nothing in the routine, not "", even after being assigned to string.empty. I know this used to work and I'm wondering if a change earlier this year from 1.1 to 2.0 / 3.0 / 3.5 treats chars differently. I can fix the code using a string instead of a char but I'm not sure why the car isn't set to an empty string either by the optional argument value or by the explicit assignment when status <> "Enabled".

Thanks in advance.
0
Comment
Question by:ZekeLA
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 33686748
There does not exist a character which equates to "empty". Strings can be empty, but characters cannot. The closes you can get is the null character, which is what I believe VB is assigning to your sBookmark.
0
 
LVL 1

Author Comment

by:ZekeLA
ID: 33686910
OK. What's strange is I checked my source control repository and this code hasn't changed in 4 years. But I know it used to work. Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now