使用VB.net/Django/PostgreSQL在表中插入条目时遇到问题

时间:2013-07-10 21:55:46

标签: django vb.net postgresql

我正在尝试在表中插入一个条目,但服务器说这个

column "Date" is of type date but expression is of type integer at character 131

这是我可以显示VB.net的SQL语句,但它是一个可怕的混乱。

INSERT INTO "Inventory_chemicalrecord"("Barcode","Action","Name_id","Building","Qty","Date") VALUES ('IEN0001','ADD',1,'Marcus',1,2013-07-10);

这是我传递的字符串

mySQLString = "INSERT INTO "&Chr(34)&"Inventory_chemicalrecord"&Chr(34)&"("&Chr(34)&"Barcode"&Chr(34)& ","&Chr(34)&"Action"&Chr(34)& ","&Chr(34)&"Name_id"&Chr(34)& ","&Chr(34)&"Building"&Chr(34)& "," &Chr(34)&"Qty"&Chr(34)& ","&Chr(34)&"Date"&Chr(34)& ") VALUES ("& code & "," &Chr(39)& Action &Chr(39) & "," & Name_id & "," & Building & ","& OriginalQty & "," & CurDate & ");"

对不起,这是我发现这样做的唯一方法,如果这是错误的方式请通知我。

我试过了

Chr(39)&CurDate&Chr(39)
"'"&CurDate&"'"

甚至设置

CurDate = Chr(39)&CurDate&CurDate(39)

我一直在期待EOF和Type&与String不匹配 有更好的方法吗?

1 个答案:

答案 0 :(得分:1)

错误信息非常清楚。

日期需要用引号括起来:'2013-07-10'

INSERT INTO "Inventory_chemicalrecord"("Barcode","Action","Name_id","Building","Qty","Date") VALUES ('IEN0001','ADD',1,'Marcus',1,2013-07-10);

应该是

INSERT INTO "Inventory_chemicalrecord"("Barcode","Action","Name_id","Building","Qty","Date") VALUES ('IEN0001','ADD',1,'Marcus',1,'2013-07-10');