?
Solved

Why is optional char argument nothing, not empty string?

Posted on 2010-09-15
2
Medium Priority
?
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 1000 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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

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.…
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 …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

765 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