📄 form4.vb
字号:
Public Class Form4
Dim objds As New Data.DataSet()
Dim objda As SqlClient.SqlDataAdapter
Dim strsql As String
Dim bindpage As BindingManagerBase
Dim n As Integer = 0
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form1.Show()
Form1.Opacity = 5
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label4.Text = ""
Dim objdr As SqlClient.SqlDataReader
Dim oconn As SqlClient.SqlConnection
Dim ocmd As SqlClient.SqlCommand
Dim strsql As String
Dim str As String
Dim n As Integer = 0
strsql = "select userid, password from mima where userid='" & TextBox1.Text & "'" ' and password= '" & TextBox2.Text & "'"
str = "Data Source= JDD;" & " Initial Catalog= student ;" & " User ID=sa;" & " Password=;"
oconn = New SqlClient.SqlConnection(str)
ocmd = New SqlClient.SqlCommand()
With ocmd
.Connection = New SqlClient.SqlConnection(str)
.Connection.Open()
.CommandText = strsql
objdr = .ExecuteReader
End With
If objdr.Read Then
With objdr
Label4.Text = .Item("userid").ToString
End With
End If
If Label4.Text <> "" Then
Label4.Text = "" & TextBox1.Text & "已存在!"
ElseIf (TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "") Then
MessageBox.Show("有空项")
ElseIf TextBox2.Text <> TextBox3.Text Then
MessageBox.Show("两次密码不一致!")
ElseIf TextBox2.Text.Length > 11 Or TextBox2.Text.Length > 11 Then
MessageBox.Show("密码超过11位!")
Else
Dim objds As New Data.DataSet()
Dim ocon As SqlClient.SqlConnection
Dim ocm As SqlClient.SqlCommand
Dim st As String
Dim strsq As String
st = "select userid, password from mima"
ocon = New SqlClient.SqlConnection(str)
objda = New SqlClient.SqlDataAdapter(st, ocon)
ocon.Open()
objda.Fill(objds, "mima")
bindpage = Me.BindingContext(objds, "mima")
bindpage.AddNew()
strsq = "insert into mima (userid ,password) values ('" & TextBox1.Text & "','" & TextBox2.Text & "')"
ocm = New SqlClient.SqlCommand(strsq, ocon)
ocm.ExecuteNonQuery()
ocon.Close()
objds.Tables("mima").NewRow()
objds.Tables("mima").AcceptChanges()
MessageBox.Show("注册成功!")
Form1.Show()
Form1.Opacity = 1
Me.Close()
End If
objdr.Close()
ocmd.Connection.Close()
End Sub
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label4.Text = ""
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -