使用VB.Net将当前时间戳插入postgresql

使用VB.Net将当前时间戳插入postgresql,vb.net,postgresql-9.3,Vb.net,Postgresql 9.3,这是我在postgresql数据库中的插入函数: Private Sub insertIntoDataBase(date As DateTime, value As String) Dim Command As NpgsqlCommand Command = New NpgsqlCommand("insert into test_base(date,value) values(" + date + "," + value ")", conn) Dim rowsaffe

这是我在postgresql数据库中的插入函数:

Private Sub insertIntoDataBase(date As DateTime, value As String)

    Dim Command As NpgsqlCommand

    Command = New NpgsqlCommand("insert into test_base(date,value) values(" + date + "," + value ")", conn)
    Dim rowsaffected As Int32
    Try
        rowsaffected = Command.ExecuteNonQuery()
        Console.WriteLine("It was added {0} lines in table table1", rowsaffected)
    Catch ex As Exception
        Console.WriteLine(ex.Message)
    End Try

End Sub

我要做的是在date字段中插入当前时间戳,而不在insert函数中传递值。与自动递增插入的字段ID类似。有可能吗?

我不知道mySql中的postgressql有可能,但在vb.net中,您可以这样更改代码:

Private Sub insertIntoDataBase(value As String)

Dim Command As NpgsqlCommand
Dim mTS as datetime = DateTime.Now

Command = New NpgsqlCommand("insert into test_base(date,value) values(" + mTS.tostring("yyyy-MM-dd HH:mm") + "," + value + ")", conn)
Dim rowsaffected As Int32
Try
    rowsaffected = Command.ExecuteNonQuery()
    Console.WriteLine("It was added {0} lines in table table1", rowsaffected)
Catch ex As Exception
    Console.WriteLine(ex.Message)
End Try

End Sub
我使用了mySql的时间戳格式:根据需要进行更改

注意:在您的代码中缺少一个+