Lab 4 Code

ViewProducts.aspx

code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ViewProducts.aspx.vb" Inherits="ViewProducts" %> <!DOCTYPE html> <html> <head><title>View Products</title></head> <body> <form id="form1" runat="server"> <h2>Product List</h2> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True" /> </form> </body> </html>

ViewProducts.aspx.vb

code

Imports System.Data Imports System.Data.SqlClient Partial Class ViewProducts Inherits System.Web.UI.Page Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load If Not IsPostBack Then LoadData() End If End Sub Private Sub LoadData() ' Connection string from Somee Dim connStr As String = "workstation id=db_talal7_07.mssql.somee.com;packet size=4096;user id=talal7_07_SQLLogin_1;pwd=kslv811wh2;data source=db_talal7_07.mssql.somee.com;persist security info=False;initial catalog=db_talal7_07;TrustServerCertificate=True" ' SQL query to get product data Dim query As String = "SELECT p.PRODUCTID, p.PRODUCTNAME, pl.PRODUCTLINENAME FROM PRODUCT p INNER JOIN PRODUCTLINE pl ON p.PRODUCTLINEID = pl.PRODUCTLINEID" ' Create the connection and command objects Using conn As New SqlConnection(connStr) Dim cmd As New SqlCommand(query, conn) Dim adapter As New SqlDataAdapter(cmd) Dim dt As New DataTable() ' Fill the DataTable with the query results adapter.Fill(dt) ' Bind the data to the GridView GridView1.DataSource = dt GridView1.DataBind() End Using End Sub End Class
Web hosting by Somee.com