Solved

Why is optional char argument nothing, not empty string?

Posted on 2010-09-15
2
356 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 74

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

17 Experts available now in Live!

Get 1:1 Help Now