Results 1 to 11 of 11

Thread: Delete From

  1. #1
    Join Date
    Sep 2003
    Location
    Recife - PE - Brazil
    Posts
    28

    Exclamation Unanswered: Delete From

    Dear friends,

    I have a table called CAT with a PK field ID_CAT where it data type is a varchar(30).
    I can post it without any error type but if I send a statement for delete a record
    using any fields in the table, the follow message error rise in a exception:


    Project DigitalCAT2004.exe raised exception class EOleException with
    message 'Syntax error converting the varchar value '01-02503/99' to a
    column of data type int'. Process stopped. Use Step or Run to continue.

    Im using Delphi with ADO components for acess the server, with Command component
    where Im using the follow statement :

    CMD.CommandText:='DELETE FROM CAT WHERE ID_CAT='+Edit1.Text;
    CMD.Execute;

    Please somebody help me cos I dont know more what I can do.
    Thanks for attetion

    Leonardo Almeida

  2. #2
    Join Date
    Nov 2003
    Posts
    94
    You need to enquote the varchar value in the command call:

    CMD.CommandText:="DELETE FROM CAT WHERE ID_CAT='"+Edit1.Text+"'";

  3. #3
    Join Date
    Sep 2003
    Location
    Recife - PE - Brazil
    Posts
    28

    Unhappy Delete from

    I did but it doesnt work... the same message rise.

  4. #4
    Join Date
    Feb 2002
    Posts
    2,232
    What is the datatype in sql server for the column ID_CAT ?

  5. #5
    Join Date
    Sep 2003
    Location
    Recife - PE - Brazil
    Posts
    28

    Exclamation Delete from

    Varchar(30)

  6. #6
    Join Date
    Dec 2003
    Posts
    454

    data type

    Based on the error message you posted, the data type of the column ID_CAT looks like int.

  7. #7
    Join Date
    Sep 2003
    Location
    Recife - PE - Brazil
    Posts
    28

    Exclamation Delete from

    Whats happen is : Using the Enterprise Manager to manipulate the table, the command execute with sucess but via my application sending the command like a stored procedure, the error rise from the server. Its seems that to execute the delete from the colum varchar used for this kind of PK ID_CAT must to be an integer datatype.
    If someone can help me Ill be thanks

  8. #8
    Join Date
    Feb 2002
    Posts
    2,232
    Post the code snippet that is executing the sql.

  9. #9
    Join Date
    Sep 2003
    Location
    Recife - PE - Brazil
    Posts
    28

    Exclamation Delete from

    CMD.CommandText:='DELETE FROM CAT WHERE ID_CAT='+Edit1.Text;
    CMD.Execute;

    as before

  10. #10
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    I don't see the quotes happening, but just to be sure, can you ( or an admin) run SQL Profiler to see what SQL Server is recieving? This will show the actual command that is given to SQL Server.

  11. #11
    Join Date
    Feb 2002
    Posts
    2,232
    You need to look into the delphi help to find out how to escape special characters - in this case (') single-quote. Normally, you can just add additional single quotes - so you would have 3 single quotes to denote a single quote inside the string and to also terminate the string.

    Maybe something like:

    CMD.CommandText:='DELETE FROM CAT WHERE ID_CAT='''+Edit1.Text+'''';

    The problem is because the data you are passing appears to be integer to sql so sql tries to do an implicit conversion on that column to integer.

Posting Permissions

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