从 sql 查询中查看到 vb.net 的数据

view data to vb.net from sql query

我有table哇

id | month    | 2015 | 2014 | 2013 |

1  | january  | 2    | 4    | 6    | 

2  | february | 10   | 12   | 14   |

3  | march    | 16   | 18   | 20   |

我有一个查询 select "2014" from waw where month ='february',结果是 12

我希望在 vb.net 中执行此查询,谁能帮助我。

问题有点不清楚(至少对我来说是这样),这样试试:

我假设您正在使用 Npgsql 作为 .Net Data Provider

Imports Npgsql

 Private Sub foo()
    Using conn As New NpgsqlConnection("pg_conn_string")
        Dim retVal As Integer
        Dim cmd As New NpgsqlCommand("", conn)
        conn.Open()
        cmd.CommandText = "select 2014 from waw where month ='february';"
        retVal = cmd.ExecuteScalar
    End Using
End Sub

您可以使用 ExecuteScalar 因为您试图只获取一个值

参考:npgsql command executescalar