C# MS-Access SQL INSERT INTO Error -
i wrote set of codes c# program insert record access database. here's code:
oledbcommand cmd = new oledbcommand("insert deployment ([datetransacted], [producttype], brand, model, serialno, assignment) values ('may 20, 2013', 'laptop', 'asus', 'k55v', 'abcd1234', '10f hrd',)", cnn); cmd.commandtype = commandtype.text; cnn.open(); cmd.executenonquery(); cnn.close(); the program executable. however, error popped saying:
syntax error in insert statement
the [datetransacted] string type. should do?
delete unnecessary comma;
oledbcommand cmd = new oledbcommand("insert deployment ([datetransacted], [producttype], brand, model, serialno, assignment) values ('may 20, 2013', 'laptop', 'asus', 'k55v', 'abcd1234', '10f hrd',)", cnn); ^^ delete you can use this;
oledbcommand cmd = new oledbcommand("insert deployment(datetransacted, producttype, brand, model, serialno, assignment) values ('may 20, 2013', 'laptop', 'asus', 'k55v', 'abcd1234', '10fhrd')", cnn); by way, datetransacted , producttype not reserved words on ms access. don't need use them square brackets.
and more important, should use parameterized queries. kind of code open sql injection attacks.
Comments
Post a Comment