vbnet_sqlserve ~ REVIEWS ALL PRODUCT JVZOO

12/08/2019

vbnet_sqlserve

Rate this posting:

Imports System.Data
Imports System.Text
Imports System.Configuration
Imports System.Data.SqlClient

Public Class About
    Inherits Page

    Private Connection As SqlConnection
    Private myCmd As SqlCommand
    Private myReader As SqlDataReader
    Private results As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            'Populating a DataTable from database.
            Dim dt As DataTable = Me.GetData()

            'Building an HTML string.
            Dim html As New StringBuilder()

            'Table start.
            html.Append("<table border = '1'>")

            'Building the Header row.
            html.Append("<tr>")
            For Each column As DataColumn In dt.Columns
                html.Append("<th>")
                html.Append(column.ColumnName)
                html.Append("</th>")
            Next
            html.Append("</tr>")

            'Building the Data rows.
            For Each row As DataRow In dt.Rows
                html.Append("<tr>")
                For Each column As DataColumn In dt.Columns
                    html.Append("<td>")
                    html.Append(row(column.ColumnName))
                    html.Append("</td>")
                Next
                html.Append("</tr>")
            Next

            'Table end.
            html.Append("</table>")

            'Append the HTML string to Placeholder.
            PlaceHolder1.Controls.Add(New Literal() With {
               .Text = html.ToString()
             })
        End If
    End Sub

    Protected Sub Login1_Authenticate(sender As Object, e As AuthenticateEventArgs) Handles Login1.Authenticate

    End Sub


    Private Function GetData() As DataTable

        Dim connetionString As String
        'connetionString = "Server=localhost;Initial Catalog=acernis;User ID=root;Password=password"
        connetionString = "server=DESKTOP-MS7EE87\LETIEN; database=constr;trusted_connection=true"
        Dim strSql As String = "SELECT * FROM Customers"
        Dim dtb As New DataTable
        Using cnn As New SqlConnection(connetionString)
            cnn.Open()
            Using dad As New SqlDataAdapter(strSql, cnn)
                dad.Fill(dtb)
            End Using
            cnn.Close()
        End Using
        Return dtb
    End Function
End Class

0 comments:

Post a Comment