---SQL Script------------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[pwd]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[pwd]
GO
CREATE TABLE [dbo].[pwd] (
[stu_id] [int] NOT NULL ,
[pwd] [char] (16) COLLATE Chinese_Taiwan_Stroke_CI_AS NOT NULL ') ON [PRIMARY]
GO
---------------------------------------------
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[stu_base]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[stu_base]
GO
CREATE TABLE [dbo].[stu_base] (
[stu_id] [int] NOT NULL ,
[point] [int] NOT NULL
) ON [PRIMARY]
GO
---------------------------------------------
declare @stu_id int
declare @pwd char(16)
--
set @stu_id = 1
set @pwd = 'pass'
--
begin transaction
insert pwd (stu_id,pwd) values(@stu_id,@pwd)
if @@error > 0 goto errH
insert stu_base (stu_id) values (@stu_id)
if @@error > 0 goto errH
commit transaction
return
--
errH:
rollback transaction
raiserror 16000 'Insert Failed! Please retry it after you confirm it.'
go
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox3.Text = "" Or TextBox4.Text = "" Then
Label35.Text = "请确认您的输入!"
Return
End If
Dim sql As String = "select * from pwd where stu_id=@stu_id and pwd=@pwd"
Dim comm As SqlCommand = New SqlCommand(sql, conn)
comm.Parameters.Add(New SqlParameter("@stu_id", SqlDbType.Int, 4))
comm.Parameters("@stu_id").Value = TextBox3.Text
comm.Parameters.Add(New SqlParameter("@pwd", SqlDbType.Char, 16))
comm.Parameters("@pwd").Value = TextBox4.Text
Dim dr As SqlDataReader
conn.Open()
dr = comm.ExecuteReader
If dr.Read Then
Session("stu_id") = TextBox3.Text
dr.Close()
comm.Cancel()
Dim sql_3 As String = "update stu_base set point=point+1 where stu_id=@stu_id"
comm = New SqlCommand(sql_3, conn)
comm.Parameters.Add(New SqlParameter("@stu_id", SqlDbType.Int, 4))
comm.Parameters("@stu_id").Value = Session("stu_id")
comm.ExecuteNonQuery()
comm.Cancel()
Response.Redirect("detail.aspx?stu_id='" & Session("stu_id") & "'")
Else
Label35.Text = "您还没有注册或账号密码错误"
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ""
TextBox2.Text = ""
End Sub