从表中获取信息作为对象

时间:2018-03-31 18:12:33

标签: sql sql-server database vb.net visual-studio

有没有办法从Visual Basic中的SQL Server中获取数据,就像在Javascript中以数据库服务器中的对象形式和PHP中的关联数组一样

在JS中

{
  id: 1,
  name: "John Doe",
  age: 24
}

在PHP中

[
  "id" => 1,
  "name" => "John Doe",
  "age" => 24
]

同样有任何方法可以在visual basic中检索和操作数据,以便我可以在MsgBox上打印

Imports System.Data.SqlClient
Public Class Form1
    Dim con As New SqlConnection("Server = DESKTOP-CAKCP8H; Database = info; Integrated Security = True")
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Try
        con.Open()
        Dim query = "select * from info"
        Dim cmd As New SqlCommand(query, con)
        Dim reader As SqlDataReader = cmd.ExecuteReader()
        reader.Read()
        /* I want here a variable which contains data like this 
          as in js 
          data = {
            id: 1,
            name: "John Doe",
            age: 24
          }
        so that i can print MsgBox(data.name) => "John Doe"*/
        con.Close()
    Catch ex As Exception
        MsgBox(ex.ToString())
    End Try
End Sub
End Class

由于我的输出是动态的,所以我不想使用索引值

0 个答案:

没有答案