Я хочу получить 1 столбец данных из DataTable, который имеет несколько столбцов и только 1 запись строки, используя VB.Net.А затем отобразить данные столбца на веб-странице с помощью ASP.Net.
В моем случае ниже я хочу получить данные столбца Name из DataTable и затем отобразить их на веб-странице.
Вот мой код VB.Net:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class TestDisplayData
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Create a Connection Object
Dim connectionString As String
Dim connection As SqlConnection
connectionString = ConfigurationManager.ConnectionStrings("SQLDbConnection").ToString
connection = New SqlConnection(connectionString)
'Create SQL Command
Dim SQL As String = "SELECT Name, Title, Phone FROM contacts"
'Open the Connection
connection.Open()
'Create DataAdaptor Object
Dim Adaptor As SqlDataAdapter = New SqlDataAdapter()
Adaptor.SelectCommand = New SqlCommand(SQL, connection)
'Close the Connection
connection.Close()
'Create DataTable Object
Dim dt As DataTable = New DataTable()
'Fill DataTable
Adaptor.Fill(dt)
'I am not sure what next code are. I want to get the Name column from the DataTable
End Sub
End Class
Вот мой код HTML ASP.Net:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Name: (I want to display the Name column data here)
</div>
</form>
</body>
</html>