Results 1 to 4 of 4

Thread: Some explanation

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Some explanation

    Can anybody explain the uses of ampersand sign over here.Kindly let me know the idea.
    Code:
    StrSql = "Select * from " & tablename

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Some explanation

    I concatenates what ever value is in tablename, if any, to the select statement. For example:

    tablename = "Contacts"

    Then StrSql will contain:

    "Select * from Contacts"

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Some explanation

    Quote Originally Posted by firoz.raj View Post
    Can anybody explain the uses of ampersand sign over here.Kindly let me know the idea.
    Code:
    StrSql = "Select * from " & tablename
    & (ampersand) concatenates two strings. In other languages this is usually done with a + (plus) operator (which you can use here also).

    So,
    StrSql = "Select * from " & tablename
    concatenates "Select * from " and tablename. Since tablename is a variable, the value of tablename is used.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Some explanation

    I'd stay away from the plus sign for concatenations as a practice. Although it will work in the example given it can cause a type mis-match error with numerics. That's just my way and that doesn't make it right. This will cause an error (lngValue can probably be wrapped to make it work but why deal with that):

    Code:
    Dim strsql As String
    Dim lngValue As Long
    
    lngValue = 10
    
    strsql = "Select * from TableName where Value = " + lngValue

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