SqlString Not Allowed with & in string


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: SqlString Not Allowed with & in string

  1. #1
    Join Date
    Jul 2004
    Posts
    143

    SqlString Not Allowed with & in string

    I found that when I use this same routine where the values are As String the string for the SQL is fine but when I change it to As SqlString I get an error

    Error 1 Operator '&' is not defined for types 'String' and 'System.Data.SqlTypes.SqlString'

    How do I create a string with a set of SQL parms where one of the values may be a SqlString since I may pass a Null.


    Public Sub Clear_TDNTRKDLM(ByRef Clr_TRK_SalesLocation As SqlString, _
    ByRef Clr_TRK_SubSalesLocation As SqlString)
    '
    On Error GoTo Clear_TDNTRKDLM_Error
    '
    Dim strDELETE_SQL As String
    '
    strDELETE_SQL = "DELETE TDNTRKMAS " & _
    "WHERE KMLOC = " & Clr_TRK_SalesLocation

    cnn.Execute(strDELETE_SQL)
    '
    Clear_TDNTRKDLM_Exit:
    Exit Sub
    '
    Clear_TDNTRKDLM_Error:
    'Call GeneralErrorRoutine(Err, "Clear_TDNTRKDLM")
    Resume Next
    '
    End Sub

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    I have never, ever used Sqlstring for a variable which contains a query.

    What is the issue with sticking with As String?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Jul 2004
    Posts
    143
    I used because the returning value from the DB can be Null. In the string case the code passes thru the error routine and keeps going. Big question was why it had an issue with the &.

  4. #4
    Join Date
    May 2004
    Location
    Duluth MN
    Posts
    353
    Try using + instead of &. + is the standard concatenation operator for SQL, although it will probably raise an error since your appending it to a string. Can't you eliminate the Nulls when retrieving the SqlString value?

    Quote Originally Posted by Don
    I found that when I use this same routine where the values are As String the string for the SQL is fine but when I change it to As SqlString I get an error

    Error 1 Operator '&' is not defined for types 'String' and 'System.Data.SqlTypes.SqlString'

    How do I create a string with a set of SQL parms where one of the values may be a SqlString since I may pass a Null.


    Public Sub Clear_TDNTRKDLM(ByRef Clr_TRK_SalesLocation As SqlString, _
    ByRef Clr_TRK_SubSalesLocation As SqlString)
    '
    On Error GoTo Clear_TDNTRKDLM_Error
    '
    Dim strDELETE_SQL As String
    '
    strDELETE_SQL = "DELETE TDNTRKMAS " & _
    "WHERE KMLOC = " & Clr_TRK_SalesLocation

    cnn.Execute(strDELETE_SQL)
    '
    Clear_TDNTRKDLM_Exit:
    Exit Sub
    '
    Clear_TDNTRKDLM_Error:
    'Call GeneralErrorRoutine(Err, "Clear_TDNTRKDLM")
    Resume Next
    '
    End Sub

    ...joe

Similar Threads

  1. Writing in HKEY_LOCAL_MACHINE...Access is denied
    By Martin in forum VB Classic
    Replies: 22
    Last Post: 12-03-2001, 03:53 AM
  2. Replies: 1
    Last Post: 06-05-2001, 06:12 AM
  3. Deadlock error.. how to remove
    By Chandra in forum VB Classic
    Replies: 0
    Last Post: 06-22-2000, 12:52 PM
  4. Please help me -- urgent -- deadlock error
    By chandra in forum VB Classic
    Replies: 0
    Last Post: 06-22-2000, 07:36 AM
  5. Replies: 0
    Last Post: 06-22-2000, 07:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center