我试图从javascript中插入/更新postgis数据库中的时间戳,但它不起作用。我在postgis中有Timestamp列,时间戳没有时区数据类型。
//My Javascript function is
function save(){
var cTime = get
WebService.saveData('Test', cTime);
}
function getTimeStamp() {
var cDate = new Date();
var sChar = String.fromCharCode(39);
var timeStamp = sChar + cDate.getFullYear() + '-' + (cDate.getMonth() + 1) + '-' + cDate.getDate() + ' ' + cDate.getHours() + ':' + cDate.getMinutes() + ':' + cDate.getSeconds() + '.' + cDate.getMilliseconds() + sChar;
//alert(timeStamp); //'2013-11-5 17:12:15.242'
return timeStamp;
}
//My webservice function is:
<WebMethod(enablesession:=True)> _
Public Function saveData( ByVal name As String,byval cTime as string) As String
try
Dim qryStr As String = "INSERT INTO ODC_Private_Graphics_Data (the_geom,timestamp) VALUES ("' & name & "'," & cTime & ")"
dbObj.Connect()
Dim insertCmd As NpgsqlCommand = New NpgsqlCommand(qryStr, dbObj.dbCon)
Dim affectedRows As Integer = insertCmd.ExecuteNonQuery
dbObj.Disconnect()
insertCmd.Dispose()
insertCmd = Nothing
Catch ex As Exception
Finally
dbObj.Disconnect()
End Try
请建议我在postgis数据库中插入时间戳的格式。提前谢谢
答案 0 :(得分:1)
在SQL表达式中使用单引号,因此结果查询将为
INSERT INTO ODC_Private_Graphics_Data(the_geom,timestamp) VALUES ('Test','2013-11-5 17:12:15.242');
双引号用于PostreSQL中的列名。