我想插入从req.body
获得的值。我将它保存在变量中,然后将它们作为插入查询中的值传递。但表中没有任何内容。
请帮帮我:
var name=req.body.Name;
var CreatedBy=req.body.CreatedBy;
var CreatedDate=req.body.CreatedDate;
var ModifiedBy=req.body.ModifiedBy;
var ModifiedDate=req.body.ModifiedDate;
var email=req.body.Email;
var idAgency= Guid();
console.log(name);
client.query('INSERT INTO Agency (idAgency ,Name,CreatedBy, CreatedDate, ModifiedBy , ModifiedDate ,Email, Active ) VALUES (idAgency ,name ,CreatedBy ,CreatedDate, ModifiedBy ,ModifiedDate,email, 1)', function(err,data){
if(err){
console.log(err);
console.log(" not inserted") ;
}
else{
console.log("insert");
console.log(data) ;
}
});
答案 0 :(得分:0)
尝试更改插入查询,如下所示:
var name=req.body.Name;
var CreatedBy=req.body.CreatedBy;
var CreatedDate=req.body.CreatedDate;
var ModifiedBy=req.body.ModifiedBy;
var ModifiedDate=req.body.ModifiedDate;
var email=req.body.Email;
var idAgency= Guid();
console.log(name);
client.query('INSERT INTO Agency (idAgency ,Name,CreatedBy, CreatedDate, ModifiedBy , ModifiedDate ,Email, Active ) VALUES (''' + idAgency + ''' ,''' +name + ''' ,''' +CreatedBy + ''' ,''' +CreatedDate + ''' , ''' +ModifiedBy + ''' ,''' +ModifiedDate + ''',''' +email + ''', '1')', function(err,data){
if(err){
console.log(err);
console.log(" not inserted") ;
}
else{
console.log("insert");
console.log(data) ;
}
});