Insert query not working in ASP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deedi
    New Member
    • May 2007
    • 11

    Insert query not working in ASP

    Hi everyone,

    I have a query which will insert records into a table . But when i execute the query in asp, it's not getting inserted in the table (the same query works well in SQL though).

    Here is my code

    qry="insert into table1(a,b,c) values(1,'1',2) "
    conn.execute qry //assume conn is eshtablished

    Please help me out to get this right.
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    Deedi,

    This is just my preference, but I like to use addnew rather than insert. addnew forces you to state each field value independently on a new line, but this makes errors more obvious. Even though it takes longer to write, it is the same execution time.

    Jared

    Comment

    • danp129
      Recognized Expert Contributor
      • Jul 2006
      • 323

      #3
      An error message might help, make sure you turn off "Show Friendly HTTP error messages" if your browser is IE.

      Are certain that column b is text field?

      I prefer using AddNew as well for most inserts.

      Also, make sure you replace single quotes with double single quotes for any user input that will be used in any SQL query like this:
      Code:
      userinputvar = Replace(userinputvar, "'", "''")
      It not only allows people submit a last name O'brian, it also stops SQL injection. If you use ADO to do rs("fieldname") =userinputvar you won't want to double your quotes for that user input, just when then input is used in an actual SELECT/INSERT/UPDATE etc.

      Comment

      • deedi
        New Member
        • May 2007
        • 11

        #4
        Hi,

        I fear that my query didn't get executed in ASP. I did a response.write to show the query. There seems no error in the query. But it is not getting executed. Is there any option to check whether the query is executed in ASP?

        Comment

        • danp129
          Recognized Expert Contributor
          • Jul 2006
          • 323

          #5
          Start a trace in SQL Profiler.

          Comment

          • deedi
            New Member
            • May 2007
            • 11

            #6
            Can you suggest me how to do a trace in ASP?

            Comment

            Working...