我通过 ODBC 将 PostgreSQL 数据库与 VB.net 一起使用,一切正常。
示例代码:
Dim reader As OdbcDataReader
Dim btCommand As OdbcCommand
Dim mCmd As OdbcCommand
Dim mCon as OdbcConnection
mCon.ConnectionString = "Dsn=PostgreSQL30;database=mydb;server=127.0.0.1;port=myport;uid=myuid;pwd=mypass"
mCon.Open()
btCommand = New OdbcCommand("BEGIN TRANSACTION", mCon)
mCmd = New OdbcCommand("SELECT dtbl_id, name, meas, price, qty, flag, kind FROM mytable WHERE dtbl_id >=" & brr.ToString & " ORDER BY dtbl_id LIMIT " & page.ToString, mCon)
reader = mCmd.ExecuteReader()
While (reader.Read())
Dim n As Integer = DataGridView1.Rows.Add()
With DataGridView1.Rows.Item(n)
.Cells(0).Value = reader.GetValue(0).ToString()
.Cells(1).Value = reader.GetValue(1).ToString()
.Cells(2).Value = reader.GetValue(2).ToString()
... etc...
但我不知道如何使用该系统(odbc)检查表是否存在以及有多少行包含到 VB 变量中,因此任何建议都将受到高度赞赏。