默认为sa。
2.完成上述步骤后进博客根目录下,找到web.config这个配置文档,用记事本方式打开这个配置文档,找到以下语句:
如果服务器在本地计算机且安装时没的更改默认配置:那么只要把"服务器IP地址"改为"localhost或 本地计算机名",把"数据库用户名"改为"blog",把"数据库用户名"改为"sa",把"数据库用户密码"改为"安装时所填写连接数据库的用户密码"。如果不是不在本地计算机上就把安装时所填写的信息填写到配置文档所对应的位置即可。
配置文档修改完成后最好把博客根目录下的名为install.aspx 和 sqlboot.aspx 这两个网页文件删除,以免重复安装造成数据库重新建立所有信息丢失的严重后果。
二、博客前台基本页面使用
1.注册页面
在首页打开注册页面,进入注册提示页面,根据注册的简要要求选择是否注册,如果同意以上要求则进入注册页面,如果反对则返回博客首页。进入注册页面后填写用户信息,用户名不重复、密码两次输入一致便可顺利注册,完成注册后返回首页并为登入状态。
2.登入页面
在首页打开登入页面,填写登入信息后,如果用户存在则进入博客首页并为登入状态,如果打开登入页面之前已为登入状态则要先登出。
3.留言页面
任何身份均可留言,未登入博客的访客身份默认为游客。
4.日志页面
默认显示所有日志,可以根据左边的栏目选择所要查看栏目日志,也可以用搜索功能搜索博客网站的日志,搜索有两种形式,一种为日志标题搜索,另一种为日志内容搜索。
5.博客首页
博客首页默认显示最新发表的日志简要内容,点击阅读则可查看日志详细内容,当访客为登入状态时则会判断登入者的身份,管理员身份登入时有权限进入后台管理,当为一般用户身份登入时则只有查看个人信息和修改个人信息的权限。
6.日志显示页面
此页面显示日志详细内容,任何身份均可进行日志评论,未登入博客的访客身份默认为游客。
7.信息显示页面
当一般用户登入时首页才显示此页面链接,其显示一般用户个人信息,可以进入信息修改页面。
8.信息修改页面
此页面只在信息显示页面提供链接,填写要更新的信息,新密码两次输入一致即可,邮箱允许为空,不填默认为没有邮箱信息,如果填写邮箱,邮箱格式不能错误,否则出错。
三、博客后台基本页面使用
1.后台登入页面
只供管理员登入,也只提供管理员在没有进入博客首页时直接进入后台时使用,只对管理员公开,填写信息为管理员身份时才可进入后台管理,当一般用户用试图登入后台管理首页时,系统会判断出其身份,然后自动退出后台首页到后台登入页面。
2.管理首页页面
只有管理员身份登入时首页才显示此链接,提供退出后台管理操作
3.日志管理页面
选择栏目添加日志,标题和内容都不能为空但不能太长,内容字数没有限制,添加成功后可随时进行栏目名修改和栏目删除操作,删除时可查询栏目后选择所要删除的日志,删除一篇日志时会自动删除它所对应的所有日志评论。
4.栏目管理页面
栏目的添加,在左边选择根栏目以添加子栏目,栏目名不能为空,添加后可随时对所添加栏目进行修改,同时不必要的栏目也可进行删除,删除时系统会自动查询栏目下有没有日志,有则需先删除,如果没有则查询栏目下有没有子栏目,有则需先删除。
5.用户管理页面
添加用户时根据所要添加的用户分配权限,信息填写正解则可添加成功,下方显示用户的详细信息,更新用户的信息时填写新的用户信息则可,注意正确填写。
6.留言管理页面
此页面只提供留言删除操作,可以具体留言删除,也可以一次性删除全部留言。
7.日志评论页面
日志的基本删除,可以逐个删除,也可以根据标题查询和栏目查询来显示所属的日志评论信息,选择要删除的日志评论。
8.日志编辑页面
此页面提供日志内容更新操作,在日志管理页面里选择编辑链接时使用。
以上使用说明为简要概述,更多的功能在使用中才更加完美体现,欢迎你使用眷海存枫博客系统。
第三章 博客系统模块分析与实现
博客安装页面
3.1建库页面
实现目标:按提示填写安装信息后,下一步进入下一页面,同时把博客数据库建立并传递连接数据库的信息。
1.建库页面(安装首页)install.aspx如下图1-1所示:
图1-1
2.设计思路
通过填写SQL服务器地址、SQL服务器用户、SQL用户密码、数据库名,点击下一步LinkButton1事件检索填写信息是否正确,如果正确则进入下一页面,如果错误则提示出错信息,返回当前页面继续填写建库信息。
3. 下一步LinkButton1_Click事件的VB代码如下:
Imports System.Data.SqlClient '包括SqlConnection或SqlCommand类
Imports System.Data '包括所有数据提供程序使用的类
Imports System.Configuration '包括连接数据库的内部命令
Protected Sub linkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim myconn As New SqlConnection
Dim mycomm As New SqlCommand
Dim ip, zh, mm, sql As String
Dim str As String
ip = Trim(TextBox1.Text) '连接数据库的IP地址
zh = Trim(TextBox2.Text) '连接数据库的用户名
mm = Trim(TextBox3.Text) '连接数据库的用户密码
sql = Trim(TextBox4.Text) '建立的博客数据库名
str = "if exists(select * from sysdatabases where name ='" & sql & "') drop database " & sql & " create database " & sql & "" '建立博客数据库SQL代码
Try
myconn.ConnectionString = "Data Source=" & ip & ";User ID= " & zh & ";Password= " & mm & ""
myconn.Open()
mycomm.CommandText = "" & str & ""
mycomm.CommandType = CommandType.Text
mycomm.Connection = myconn
mycomm.ExecuteNonQuery() '提交服务器内部执行
Catch ex As Exception
myconn.Dispose()
mycomm.Dispose()
Response.Write("
") '连接失败时所要提示的信息
End Try
mycomm.Dispose() '释放空间
myconn.Dispose() '释放空间
Response.Write("
") '连接建库成功时所要提示的信息并传递连接数据库信息到下一页
End Sub
3.2建表页面
实现目标:实行建表跟建立管理员用户操作,按提示填写建表信息,正确填写按下一步完成建表安装操作。
1.建表页面sqlboot.aspx如下图1-2所示:
图1-2
2.设计思路
通过填写管理员用户跟密码,点击下一步LinkButton1事件检索填写信息是否正确,如果正确则实行建表操作,建表成功后提示删除安装页面,如果错误则提示出错信息,返回当前页面继续填写建表信息。
3. Page_Load 和下一步LinkButton1_Click事件的VB代码如下:
Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
Dim ip, zh, mm, sql As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ip = Request.QueryString("ip") '获取连接数据库的IP地址
zh = Request.QueryString("zh") '获取连接数据库的数据库用户名
mm = Request.QueryString("mm") '获取连接数据库的数据库用户密码
sql = Request.QueryString("sql")'获取连接数据库的数据库名
End Sub
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim root, login, qr, group As String
group = "管理员"
root = Trim(TextBox1.Text)
login = Trim(TextBox2.Text)
qr = Trim(TextBox3.Text)
If root = "" Then
root = "admin" '默认情况下添加的管理员账号为"admin"
End If
If login = "" Then
Response.Write("
")
Return
End If
If login <> qr Then
Response.Write("
")
Return
End If
Dim myconn As New SqlConnection
Dim mycomm As New SqlCommand
Dim str As String
str = "create table 日志栏 (id int identity primary key,txt char(40) not null,rootid int not null)"
str = str & " create table 日志库 (id int identity primary key,栏目id int not null,标题 nchar(60) not null,内容 ntext not null,时间 datetime,首页显示 char(250) not null)"
str = str & " create table 日志留言 (id int identity primary key,账号 char(20) not null,留言 char(800) not null,时间 datetime,系号 int not null,标题 nchar(60) not null,所属 char(40))"
str = str & " create table 留言 (系号 int identity primary key,账号 char(20) not null,内容 char(800) not null,时间 datetime)"
str = str & " create table 账户 (账号 char(20) primary key,密码 char(20) not null,邮箱 char(25),用户组 char(10) not null)"
str = str & " insert 账户(账号,密码,用户组) values(@zh,@mm,@group)" '建表SQL代码
Try
myconn.ConnectionString = "Data Source=" & ip & ";User ID= " & zh & ";Password= " & mm & "" '连接数据库
myconn.Open()
mycomm.CommandText = "use " & sql & " " & str & "" '建表代码集
mycomm.Parameters.Add("@zh", SqlDbType.Char).Value = root
mycomm.Parameters.Add("@mm", SqlDbType.Char).Value = login
mycomm.Parameters.Add("@group", SqlDbType.Char).Value = group
mycomm.Connection = myconn
mycomm.ExecuteNonQuery()
Catch ex As Exception
myconn.Dispose()
mycomm.Dispose()
Response.Write("
")
End Try
myconn.Dispose()
mycomm.Dispose()
LinkButton1.Visible = False
Label1.Visible = False
Label2.Visible = False
Label3.Visible = False
Label5.Visible = False
TextBox1.Visible = False
TextBox2.Visible = False
TextBox3.Visible = False
Label4.Text = "完成安装,进入根文件夹下把 install.aspx 和 sqlboot.aspx 这两个网页文件删除" '完成安装时建表页面显示的提示信息
End Sub
博客前台页面
3.3博客首页
实现目标:显示最新日志简要内容,可以根据选择进入日志、留言、登入、注册页面,有比较综合的链接显示。
1.博客首页index.aspx如下图1-3所示:
2.设计思路
在首页TreeView1显示日志栏目GridView1显示最新日志信息,可以直接选择要看的日志栏目链接到日志页面并且显示链接栏目下的子日志,还可以根据直接查看最新日志。登入后的用户根据身份验证LinkButton1显示后台管理链接或个人信息管理链接,信息显示页面由此页面的个人信息管理链接引导,只供一般用户使用,在信息显示页面(以下3.9会有详细介绍)可以进入信息修改页面(以下3.10会有详细介绍),如果用户登入后要继续登入,首页在用户登入后有登出操作。
3.页面添加代码如下所示:
显示控件GridView1所要添加TemplateField的列为"查看",页面所要添加的代码为:
"target="" >阅读
图1-3
Page_load和createchildtree过程的VB代码:
Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
Dim uid As String
Dim group As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
uid = Session("uid") '获取登入用户的用户名
If Not Page.IsPostBack Then
If uid <> "" Then
Label2.Text = uid
Dim myconn As New SqlConnection
Dim mycomm As New SqlCommand
Dim myreader As SqlDataReader
myconn.ConnectionString = ConfigurationManager.ConnectionStrings("conn").ConnectionString
myconn.Open()
mycomm.CommandText = "select count(*) from 账户 where 账号=@uid and 用户组='管理员'"
mycomm.Parameters.Add("@uid", SqlDbType.Char).Value = uid
mycomm.CommandType = CommandType.Text
mycomm.Connection = myconn
myreader = mycomm.ExecuteReader
myreader.Read()
group = myreader.GetValue(0) '判断登入者是否为管理员
myreader.Close()
If group <> 0 Then
LinkButton1.Text = "后台管理"
LinkButton1.PostBackUrl = "~/adminpage.aspx" '管理员登入时链接
Else
LinkButton1.Text = "个人信息管理"
LinkButton1.PostBackUrl = "~/user.aspx" '一般用户登入时链接
End If
Else
Label1.Visible = False
Label2.Visible = False
LinkButton1.Visible = False
LinkButton2.Text = "欢迎你来到眷海存枫博客" '匿名访问时显示
LinkButton2.PostBackUrl = "~/index.aspx" '匿名访问时显示文字的链接
End If
Dim tn As New TreeNode
tn.Text = "首页"
tn.NavigateUrl = ("date.aspx")
createchildtree(tn, 0) '调用过程
TreeView1.Nodes.Add(tn)
End If
End Sub
Protected Sub createchildtree(ByVal parentnode, ByVal parentid) '树目录的过程
Dim myconn As New SqlConnection
Dim mycomm As New SqlCommand
Dim myreader As SqlDataReader
Dim tn As TreeNode
myconn.ConnectionString = ConfigurationManager.ConnectionStrings("conn").ConnectionString
myconn.Open()
mycomm.CommandText = "select * from 日志栏 where rootid=@rootid"
mycomm.Parameters.Add("@rootid", SqlDbType.Int).Value = parentid
mycomm.CommandType = CommandType.Text
mycomm.Connection = myconn
myreader = mycomm.ExecuteReader()
Do While myreader.Read() '从表的第一行开始读取
tn = New TreeNode
tn.Text = myreader("txt").ToString
tn.NavigateUrl = "date.aspx? &id=" & myreader("id")
createchildtree(tn, myreader("id")) '树的递归调用
parentnode.childnodes.add(tn) '添加子树
Loop
myreader.Close()
mycomm.Dispose()
myconn.Dispose()
End Sub
登出按钮LinkButton2_Click事件代码如下:
Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton2.Click
Session("uid") = "" '登出,把传递的用户名置为空
Response.Redirect("index.aspx") '返回博客首页
End Sub
3.4日志页面
实现目标:查看日志和搜索日志,搜索日志可以根据日志标题,也可以根据日志内容。左边目录树查看日志栏目下所有的日志。
1.日志页面date.aspx如下图1-4所示:
2.设计思路
在日志页面默认打开时GridView1显示所有的日志,左边栏目TreeView1可以选择所要对应栏目下日志,日志显示栏可以直接点击查看链接查看日志详细内容,Button1_Click事件提供日志搜索,根据标题搜索,也可以根据内容搜索,搜索显示日志标题而不显示日志内容,日志详细内容是在日志显示页面(以下3.11会有详细介绍)显示。
3.页面添加代码如下所示:
显示控件GridView1所要添加TemplateField的列为"日志查看",页面所要添加的代码为:
"target="" >查看
日志搜索按钮Button1_Click事件VB代码:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String
str = DropDownList1.SelectedValue '取出选择搜索的条件
If str = "日志标题" Then '选择搜索的条件为日志标题
SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings("conn").ConnectionString
SqlDataSource1.SelectCommand = "select id,标题,时间 from 日志库 where 标题 like'%" & TextBox1.Text & "%' order by 时间 desc"
Else
If str = "日志内容" Then '选择搜索的条件为日志内容
SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings("conn").ConnectionString
SqlDataSource1.SelectCommand = "select id,标题,时间 from 日志库 where 内容 like'%" & TextBox1.Text & "%' order by 时间 desc"
End If
End If
End Sub
图1-4
Page_load和createchildtree过程的VB代码:
Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
Dim dateid As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
dateid = Request.QueryString("id")
Dim myconn As New SqlConnection
Dim mycomm As New SqlCommand
Dim tn As New TreeNode
tn.Text = "首页"
tn.NavigateUrl = ("date.aspx")
createchildtree(tn, 0)
TreeView1.Nodes.Add(tn)
If dateid <> "" Then
SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings("conn").ConnectionString
SqlDataSource1.SelectCommand = "select id,标题,时间 from 日志库 where 栏目id='" & CInt(dateid) & "' order by 时间 desc"
Else
SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings("conn").ConnectionString
SqlDataSource1.SelectCommand = "select id,标题,时间 from 日志库 order by 时间 desc"
End If
End If
End Sub
Protected Sub createchildtree(ByVal parentnode, ByVal parentid) '树目录的过程
Dim myconn As New SqlConnection
Dim mycomm As New SqlCommand
Dim myreader As SqlDataReader
Dim tn As TreeNode
myconn.ConnectionString = ConfigurationManager.ConnectionStrings("conn").ConnectionString
myconn.Open()
mycomm.CommandText = "select * from 日志栏 where rootid=@rootid"
mycomm.Parameters.Add("@rootid", SqlDbType.Int).Value = parentid
mycomm.CommandType = CommandType.Text
mycomm.Connection = myconn
myreader = mycomm.ExecuteReader()
Do While myreader.Read()
tn = New TreeNode
tn.Text = myreader("txt").ToString
tn.NavigateUrl = "date.aspx?id=" & myreader("id")
createchildtree(tn, myreader("id"))
parentnode.childnodes.add(tn)
Loop
myreader.Close()
mycomm.Dispose()
myconn.Dispose()
End Sub
3.5留言页面
实现目标:留言页面显示留言信息,并供所有身份的用户留言。
1.留言页面massage.aspx如下图1-5所示:
2.设计思路
当访问者访问留言页面时,通过验证这个访问者是否登入博客,而不验证访问者的身份和权限,留言是自由的,GridView1显示所有的留言,而当访问者为游客时,提示为游客身份,显示"现在注册"链接,Button1_click事件提交对博客的留言内容,并验证留言是否为空。
3.页面添加代码如下所示:
Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
图1-5
Page_load和提交按钮Button1_click、重置按钮Button2_click事件的VB代码:
Dim uid As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
uid = Session("uid")
Label2.Text = uid
If uid = "" Then
CheckBox1.Checked = True
Label2.Text = "游客" '没有登入默认为"游客"
Else
Label1.Text = "你已登入博客网站: " '登入博客时的提示信息
HyperLink1.Visible = False
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
Response.Write("
")
Return
End If
Dim myconn As New SqlConnection
Dim mycomm As New SqlCommand
myconn.ConnectionString = ConfigurationManager.ConnectionStrings("conn").ConnectionString
myconn.Open()
mycomm.CommandText = "insert into 留言 (账号,内容,时间) values (@zh,@nr,@sj)"
mycomm.Parameters.Add("@zh", SqlDbType.Char).Value = Label2.Text
mycomm.Parameters.Add("@nr", SqlDbType.Char).Value = TextBox1.Text
mycomm.Parameters.Add("@sj", SqlDbType.DateTime).Value = Now
mycomm.CommandType = CommandType.Text
mycomm.Connection = myconn
Try
mycomm.ExecuteNonQuery()
Catch ex As Exception
mycomm.Dispose()
myconn.Dispose()
Response.Write("
")
Return
End Try
Page.Response.Redirect("massage.aspx")
mycomm.Dispose()
myconn.Dispose()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
End Sub
3.6登入页面
实现目标:当登入用户输入的账号跟密码正确时,成功登入博客页面,然后跳转到博客首页。
1.登入页面login.aspx如下图1-6所示:
图1-6
2.设计思路
登入页面只有用户名跟密码的输入框,输入信息后按登入按钮触发Button1_Click事件,检查输入的用户名和密码,查找博客数据库里是否存在此用户,如果存在,则跳转到博客首页,Page_Load事件查看实行登入操作的访问者是否登入,如果已登入则提示先登出。
3.页面添加代码如下所示:
Page_Load 和登入按钮Button1_click事件的VB代码:
Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
Dim uid As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
uid = Session("uid") '取上一页传递过来的参数
If uid <> "" Then
Response.Write("
")
End If
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myconn As New SqlConnection
Dim mycomm As New SqlCommand
Dim myread As SqlDataReader
Dim count As Integer
Dim zh, mm As String
zh = Trim(TextBox1.Text)
mm = Trim(TextBox2.Text)
myconn.ConnectionString = ConfigurationManager.ConnectionStrings("conn").ConnectionString
myconn.Open()
mycomm.CommandText = "select count(*) from 账户 where 账号=@zh and 密码=@mm"
mycomm.Parameters.Add("@zh", SqlDbType.Char).Value = zh
mycomm.Parameters.Add("@mm", SqlDbType.Char).Value = mm
mycomm.CommandType = CommandType.Text
mycomm.Connection = myconn
myread = mycomm.ExecuteReader
myread.Read()
count = myread.GetValue(0)
myread.Close()
If count <> 0 Then
Session("uid") = zh
Page.Response.Redirect("index.aspx")
Else
mycomm.Dispose()
myconn.Dispose()
Response.Write("
")
Return
End If
myconn.Dispose()
mycomm.Dispose()
End Sub
3.7注册页面
实现目标:博客的用户注册,注册的用户的身份为一般用户。
1.留言页面register.aspx如下图1-7所示:
2.设计思路
访问者填写好注册信息后,通过Button1_click事件验证输入的用户名是否重复、密码是否一致,RegularExpressionValidator1检验邮箱不为空时格式是否正确。
3.页面添加代码如下所示:
提交按钮Button1_click和重置按钮Button2_click事件的VB代码:
Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
图1-7
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim zh, mm, yx, qr, group As String
group = "一般用户"
zh = Trim(TextBox1.Text)
mm = Trim(TextBox2.Text)
qr = Trim(TextBox3.Text)
yx = Trim(TextBox4.Text)
If zh = "" Then
Response.Write("
")
Return
End If
If mm = "" Then
Response.Write("
")
Return
End If
If mm <> qr Then
Response.Write("
")
Return
End If
Dim myconn As New SqlConnection
Dim mycomm As New SqlCommand
myconn.ConnectionString = ConfigurationManager.ConnectionStrings("conn").ConnectionString
myconn.Open()
mycomm.CommandText = "insert into 账户 (账号,密码,邮箱,用户组) values (@zh,@mm,@yx,@group)"
mycomm.Parameters.Add("@zh", SqlDbType.Char).Value = zh
mycomm.Parameters.Add("@mm", SqlDbType.Char).Value = mm
mycomm.Parameters.Add("@yx", SqlDbType.Char).Value = yx
mycomm.Parameters.Add("@group", SqlDbType.Char).Value = group
mycomm.CommandType = CommandType.Text
mycomm.Connection = myconn
Try
mycomm.ExecuteNonQuery()
Session("uid") = zh
Catch ex As Exception
mycomm.Dispose()
myconn.Dispose()
Response.Write("
")
Return
End Try
Page.Response.Redirect("index.aspx")
mycomm.Dispose()
myconn.Dispose()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
3.8注册提示页面
实现目标:注册者查看注册信息,选择是否注册,选同意跳转到注册页面,反对则返回首页。
1.注册提示页面maple.aspx如下图1-8所示:
图1-8
2.设计思路
注册者阅读注册要求后选择是否要注册,LinkButton1_Click事件返回到博客首页,而第二个LinkButton2_Click事件是进入到注册页面。
3.页面添加代码如下所示:
反对链接LinkButton1_Click和同意链接LinkButton2_Click事件的VB代码:
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Page.Response.Redirect("index.aspx")
End Sub
Protected Sub LinkButton2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton2.Click
Page.Response.Redirect("register.aspx")
End Sub
3.9信息显示页面
实现目标:让一般用户查看其个人信息,并可选择修改信息。
1.信息显示页面user.aspx如下图1-9所示:
图1-9
2.设计思路
页面显示用户的所有信息,Page_Load事件读取相看信息的一般用户的用户信息,Button1_Click事件传递用户名并进入修改信息页面。
3.页面添加代码如下所示:
Page_Load 和修改信息按钮Button1_click事件的VB代码:
Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
Dim uid As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
uid = Session("uid")
If uid <> "" Then
Dim myconn As New SqlConnection
Dim mycomm As New SqlCommand
Dim myread As SqlDataReader
Dim zh, yx As String
myconn.ConnectionString = ConfigurationManager.ConnectionStrings("conn").ConnectionString
myconn.Open()
mycomm.CommandText = "select * from 账户 where 账号='" & uid & " '"
mycomm.CommandType = CommandType.Text
mycomm.Connection = myconn
myread = mycomm.ExecuteReader
myread.Read()
zh = myread.GetString(0)
yx = myread.GetString(2)
myread.Close()
Label3.Text = zh
Label7.Text = yx
myconn.Dispose()
mycomm.Dispose()
End If
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles But
上一篇:
基于ASPNET技术的WEB网站开发与设计
下一篇:
大山不曾给我许诺