Syntax error in INSERT INTO statement in c# oledb?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ayaz1982
    New Member
    • Apr 2010
    • 1

    #1

    Syntax error in INSERT INTO statement in c# oledb?

    I am having a table called SubMaster_Accou nts, which contains 9 fields. In which I want to insert data to some fields and i want to store some other fields as NULL. I tried to write the query using query string, but it shows syntax error in Insert command. How can i do it?

    Code:
    insert into SubMaster_Account ([SMcode], [MSname], [Sname], [Openbalrs],
     [Openbalrs1], [Openbalmet], [Openbalmet1], [Creditdays], [Sdesc])
     values ('" + SMcode + "','" + MSname + "','" + Sname + "'," + 
    Openbalrs + ",'" + Openbalrs1 + "'," + Openbalmet + ",'" + 
    Openbalmet1 + "'," + Creditdays + ",'" + Sdesc + "')
    Last edited by tlhintoq; Apr 22 '10, 03:51 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    A little hulky, but your SQL statement looks fine.

    Are you remembering to check all your string fields for embedded single quotes ' ? And then escaping them out by adding another single quote ('' is not ")

    Comment

    Working...