CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2005
    Posts
    10

    Question SqlCommand Text problem

    Hi,

    I have a 2 drop down lists. The first list contains alphabets from A-Z. When the user selects a an alphabet in the first list, the second list gets populated (from the database) with all customer names beginning with that alphabet.

    But I am facing problem with the SQL command to get values from the
    Database.I am using the sqlCommand text as :
    SELECT CustName FROM Table WHERE (CustName LIKE @x)

    Here @x (the parameter) is the alphabet which the user selects from the
    first dropdown list. Now, I want all CustNames which start with the letter
    chosen by the user.

    I tried the command with a % sign after the parameter like
    SELECT CustName FROM Table WHERE (CustName LIKE @x%)
    but it said Syntax is wrong. I even tried '@x*' and '@x%' and even @x %25 , but nothing
    seems to work.

    What is the right syntax for this?
    Please help.

    Thanks

  2. #2
    Join Date
    Jan 2005
    Posts
    10

    Thumbs up Re: SqlCommand Text problem

    Hi,

    I found out the answer. the correct syntax is SELECT CustName from table WHERE (CustName Like @x +'%').

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