都是用SQL,什么数据库没关系,就是连接的时候不一样
Private Sub BtnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'去掉信息中的空格,避免只有空格的信息输入
Dim Text1, Text2, Text3 As String
Text1 = Trim(name.Text)
Text2 = Trim(pwd1.Text)
Text3 = Trim(pwd2.Text)
'防止输入空信息
If Text1 = "" Or Text2 = "" Or Text3 = "" Then
Response.Write("<script>alert('请输入完整信息!');history.go(-1)</script>")
End If
'检查用户名是否存在
OleDbCommand1.CommandText = "select * from 用户 where ='" & Text1 & "'"
OleDbConnection1.Open()
Dim sqlreader As OleDbDataReader = OleDbCommand1.ExecuteReader
If sqlreader.Read() Then
TextBox1.Text = ""
Response.Write("<script>alert('该用户已存在,请您取个新名字!');history.go(-1)</script>")
End If
sqlreader.Close()
OleDbConnection1.Close()
'判断两次输入密码是否相同
If Text2 <> Text3 Then
TextBox2.Text = ""
TextBox3.Text = ""
Response.Write("<script>alert('两次密码输入不同,请重新输入!');history.go(-1)</script>")
Else
'将注册信息写入数据库
OleDbCommand1.CommandText = "insert into 用户(用户名,密码) values('" & Text1 & "','" & Text2 & "')"
OleDbConnection1.Open()
OleDbCommand1.ExecuteNonQuery()
OleDbConnection1.Close()
End If
End Sub
我自己编的,也是初学者,嘿嘿!OleDbConnection1 的连接要自己设置
[此贴子已经被作者于2006-5-26 3:56:00编辑过]