标题:VB代码改写
只看楼主
youshuling520
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2008-5-25
 问题点数:0 回复次数:1 
VB代码改写
以下是一个登入界面的代码,请问那个高手可以帮我把下面得代码改成用一个类分装,然后用一个摁钮来调用~~~
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
            'Call DBopen()
            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
搜索更多相关主题的帖子: System Text 代码 And ByVal 
2008-05-30 21:31
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
得分:0 
你能不能发到版面去?这里不讨论,谢谢合作!
2008-05-30 21:34



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-216757-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.079850 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved