呀!救命呀~~~高手们
有那个高手可以帮我把下面的语言写的登入界面的代码改成用一个类封装起来 然后在用一个Button去调用不??Imports System.Data
Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Public t As New DataTable
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connectionString As String
If txtName.Text <> "" And txtPassword.Text = "" Then
MsgBox("请输入密码!", , "提示")
ElseIf txtName.Text = "" And txtPassword.Text <> "" Then
MsgBox("请输入帐号!", , "提示")
ElseIf txtName.Text = "" And txtPassword.Text = "" Then
MsgBox("请输入帐号和密码!", , "提示")
Else
Dim connectionString As String
connectionString = "server=(local);database=Northwind;uid=sa"
Dim connector As New SqlConnection
connector.ConnectionString = connectionString
Dim commander As New SqlCommand
= "SELECT name FROM users WHERE name=@name AND password=@password"
= CommandType.Text
commander.Connection = connector
Dim parPassword As New SqlParameter
parPassword.ParameterName = "@password"
parPassword.SqlDbType = SqlDbType.Char
parPassword.Size = 20
parPassword.Value = Me.txtPassword.Text
parPassword.Direction = ParameterDirection.Input
Dim parName As New SqlParameter
parName.ParameterName = "@name"
parName.SqlDbType = SqlDbType.Char
parName.Size = 20
parName.Value = Me.txtName.Text
parName.Direction = ParameterDirection.Input
commander.Parameters.Add(parName)
commander.Parameters.Add(parPassword)
Try
connector.Open()
Dim reader As SqlDataReader = commander.ExecuteReader(CommandBehavior.CloseConnection)
If reader.HasRows Then
MessageBox.Show("登入成功!")
Dim f As New Form3
f.Show()
End If
reader.Close()
Catch ex As Exception
MessageBox.Show("登入失败!")
Finally
If connector.State = ConnectionState.Open Then
connector.Close()
End If
If Not (connector Is Nothing) Then
connector.Dispose()
End If
If commander.Parameters.Count > 0 Then
commander.Parameters.Clear()
End If
If Not (commander Is Nothing) Then
commander.Dispose()
End If
End Try
End If
'If result Then
' MessageBox.Show("成功啦!")
'End If
End Sub