Solved

Why is optional char argument nothing, not empty string?

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

713 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