Solved

Why is optional char argument nothing, not empty string?

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2013 and Eclipse Neon 6 36
Help with error when uploading excel file 3 27
Modal Popup Extender control 1 20
Regular expression help 2 25
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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