CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: HELP with SQL and strings

    You didn't say which SQL Server, but you can use this with MS SQL Server.

    have to translate from VB6

    Code:
    Option Explicit
    
    Private Sub Form_Load()
    Dim strsql$, strlength$
    Dim strFeet$, strInch$
    strFeet = "10"
    strInch = "11"
    strlength = strFeet & "'" & "x" & strInch & Chr(34)
    strsql = "INSERT items values('Board', '" & CleanText(strlength) & "')"
    MsgBox strsql
    Debug.Print strsql
    End Sub
    
    Public Function CleanText(strIn As String) As String
        On Error GoTo VBError
        
        Dim iAcnt As Long
        Dim strString As String
        Dim vLimit As Long
        vLimit = Len(strIn)
        For iAcnt = 1 To vLimit
            Select Case Asc(Mid$(strIn, iAcnt, 1))
            Case 10, 13
                strString = strString & Mid$(strIn, iAcnt, 1)
            Case 124
                strString = strString & "!"
            Case 39
                strString = strString & "''"
            Case 34
                strString = strString & """"
            Case Is < 32
                strString = strString & " "
            Case Is > 126
                strString = strString & " "
            Case Else
                strString = strString & Mid$(strIn, iAcnt, 1)
            End Select
            Next
        CleanText = strString
    Exit Function
    VBError:
        MsgBox "VBError in Sub Parse_SQL_Text : " & Err.Number & " - " & Err.Description
        Resume Next
    End Function
    Last edited by dglienna; August 8th, 2008 at 01:43 AM.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured