Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2003
    Posts
    21

    Unanswered: Recordet Problem

    I'm creating a Visual Basic program linked to an SQL server DB. In one of my tables I have a field for phone number which is an nvarchar datatype that is stored in the following format (example: 617-782-6415).

    I have a form where I want to view the contents of the following recordset:

    SELECT d .ACCOUNT_CODE, d .DURATION, d .[DATE], d .[HOUR], d .NUMBER_DIALED, p.ACCOUNT_CODE AS Expr1, p.LAST_NAME, p.FIRST_NAME,
    p.SUMMARY_GROUP, p.DIRECT_DIAL, p.TITLE, p.LOCATION, p.DIVISION, p.DEPARTMENT, p.DIRECTOR, p.OLD_CARD_NUM, p.REISSUE, p.CLASS,
    p.PHONE
    FROM DETAIL d INNER JOIN
    PHONE_EMP_MAST p ON d .ACCOUNT_CODE = p.ACCOUNT_CODE
    WHERE number_dialed = " & astring & "


    The value for astring is pulled from a combobox that stores all the values for number_dialed. However when i run this program i get the error message

    "syntax error converting the nvarchar value '401-781-7078' to a column of datatype int"

    I dont need to convert it to a column of datatype int so I dont understand this error... can anyone help me?

  2. #2
    Join Date
    Oct 2001
    Location
    England
    Posts
    426
    The only thing that can be forcing a convertion is

    WHERE number_dialed = " & astring & "

    What is this tryin to do?
    Take one value frm teh combo box?
    I assume as you have " as the string delimitter then you are trying to form the select in VB.
    You would be better to create an SP and pass the parameter.
    For your string here try

    WHERE number_dialed = '" & astring & "'"


    i.e. making astring into a string in the query.

  3. #3
    Join Date
    Feb 2003
    Posts
    21
    Yeah, I'm trying to form the select in VB because I'm more familiar with that way... I'd prefer to do it in VB if at all possible... Why is it converting it?

  4. #4
    Join Date
    Oct 2001
    Location
    England
    Posts
    426
    WHERE number_dialed = " & astring & "

    will give something like

    WHERE number_dialed = 617-782-6415

    it will evaluate 617-782-6415 giving a negative number then try to convert number_dialed to an integer for the compare.

    you need
    WHERE number_dialed = '617-782-6415'
    to do a string compare
    hence the quotes in my previous 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
  •