VB .net 从数据表中读取

VB .net Reading from Datatable

正在尝试修改 http://www.codeproject.com/Tips/698656/How-to-create-a-Google-Heatmap-in-VB-NET 以便我可以从我的数据库中读取热图数据,这是我所拥有的:

Protected Sub btnFetch_Click(sender As Object, e As EventArgs) Handles btnFetch.Click
    ' here you should insert a call to a database fetching coordinates
    ' something like Call Public Function GetLocationData

    'I simulate the fetching of different data by setting a toggle variable in viewstate
    Dim toggle As Boolean
    If (Me.ViewState("toggle") IsNot Nothing) Then
        toggle = CType(Me.ViewState("toggle"), Boolean)
    Else
        toggle = False
    End If

    Dim myData As DataTable
    Dim conn As New SqlConnection()
    Dim cmd As New SqlCommand
    Dim previousConnectionState As ConnectionState = conn.State
    conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("SeismicData").ConnectionString
    cmd.CommandText = "SELECT Lat,long,Ss from SeismicData"
    cmd.Connection = conn
    Dim reader1 As SqlDataReader
    If conn.State = ConnectionState.Closed Then conn.Open()
    reader1 = cmd.ExecuteReader
    myData.Load(reader1)
    If previousConnectionState = ConnectionState.Open Then conn.Close()

    Dim oGeocodeList As List(Of String)
    If Not toggle Then
        oGeocodeList = New List(Of String)() From { _
                                                        "  '59.4847444, 17.749211'", _
                                                        "  '59.4209403, 17.797933 '", _
                                                        "  '59.5150872, 17.6437817 '" _
                                                        }
        Me.ViewState.Add("toggle", True)
    Else
        oGeocodeList = New List(Of String)() From {" '59.3289, 18.06491'"}
        Me.ViewState.Add("toggle", False)
    End If

    Dim geocodevalues = String.Join(",", oGeocodeList.ToArray())

    'here I inject a variable containing the coordinates in the page
    ClientScript.RegisterArrayDeclaration("locationList", geocodevalues)
End Sub

我不知道如何用 mydata 替换 oGeocodeList,你能帮忙吗?

谢谢

您不需要 myData,只需循环 reader 并将数据添加到列表。

Do While reader1.Read
    oGeocodeList.Add(String.Format("'{0},{1}'", reader1.GetString(0), reader1.GetString(1)))
Loop