0

我想插入我从中得到的值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) ;
    }
});
4

1 回答 1

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) ;
    }
});
于 2013-05-20T12:05:12.940 回答