我想执行我的postgres函数,在VBNet中将日期作为参数,并在datagridview中显示结果.Below是我的代码请告诉我哪里出错了。我想我写错了命令来执行函数。我知道这个可能是错误的方式,但我在VBNet中使用第一次postgres功能
Imports Npgsql
Public Class Form1
Dim connstring As String = String.Format("Server=127.0.0.1;Port=5432;" +
"Username=xxxx;Password=xxxx;Database=EMS_Demo_db;")
Dim conn As NpgsqlConnection = New NpgsqlConnection(connstring)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try
conn.Open()
Dim Command As NpgsqlCommand = New NpgsqlCommand("SELECT * FROM lastsevendays_sp ' + DateTimePicker1.Value + '", conn)
Dim reader As NpgsqlDataReader = Command.ExecuteReader()
Dim data_Table1 As New DataTable
data_Table1.Load(reader)
DataGridView1.DataSource = data_Table1
reader.Close()
conn.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class

答案 0 :(得分:0)
你错过了一个括号 - 在PostgreSQL SQL中必须使用括号:
应该是:
Dim Command As NpgsqlCommand = New NpgsqlCommand("SELECT * FROM lastsevendays_sp( ' + DateTimePicker1.Value + ')", conn)
我不是.NET专家,所以我不知道真正的解决方案,但有两个风险: