0

I have tried to insert/update the timestamp in postgis database from javascript, But its not working. I have Timestamp column in postgis with Timestamp without time zone data type.

 //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

Please suggest me the format for inserting timestamp in postgis database.Thanks in advance

4

1 回答 1

1

在 SQL 表达式中使用单引号,因此您的结果查询将是

INSERT INTO ODC_Private_Graphics_Data(the_geom,timestamp) VALUES ('Test','2013-11-5 17:12:15.242');

双引号用于 PostreSQL 中的列名。

于 2013-11-06T02:55:50.663 回答