Imports System.Data
Imports System.Data.SqlClient
Public Class showarticle
Inherits System.Web.UI.Page
Dim cn As New SqlConnection("server=localhost;uid=sa;pwd=123;database=article;")
Dim cm As SqlCommand
Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Table3 As System.Web.UI.HtmlControls.HtmlTable
Protected WithEvents pageTitle As System.Web.UI.HtmlControls.HtmlGenericControl
Protected WithEvents keyword As System.Web.UI.HtmlControls.HtmlGenericControl
Dim stid As String
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
stid = Request.QueryString("name")
Dim str As String
cm = New SqlCommand("select text from article where artname= '" & stid & "'", cn)
cn.Open()
str = cm.ExecuteScalar
If cm.ExecuteScalar Is Nothing Then
exitsub()
Exit Sub
End If
Label1.Text = str.Replace(vbCrLf, "<br>")
cn.Close()
title()
related()
End Sub
Sub related()
Dim cat2 As String
cm = New SqlCommand("select artcat2 from article where artname= '" & stid & "'", cn)
cn.Open()
cat2 = cm.ExecuteScalar
cn.Close()
relatedlink(cat2)
End Sub
Sub relatedlink(ByVal cat2 As String)
Dim da As New SqlDataAdapter("select top 5 artname from article where artcat2 = '" & cat2 & "' and artname <> '" & stid & "'", cn)
Dim ds As New DataSet()
cn.Open()
da.Fill(ds)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
cn.Close()
End Sub
Sub title()
stid = Request.QueryString("name")
Dim dr As SqlDataReader
cm = New SqlCommand("select keyword from article where artname = '" & stid & "'", cn)
cn.Open()
Label2.Text = cm.ExecuteScalar
cn.Close()
pageTitle.InnerText = Label2.Text
End Sub
Sub exitsub()
Label2.Text = "Article Not Exist"
End Sub
Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
cm = New SqlCommand("select artcat2 from article where artname ='" & stid & "'", cn)
Dim cat As Integer
cn.Open()
cat = cm.ExecuteScalar
cn.Close()
Response.Redirect("relatedarticle.aspx?cat=" & cat)
End Sub
End Class