| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 660 人关注过本帖
标题:呀!救命呀~~~高手们
只看楼主 加入收藏
youshuling520
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2008-5-25
收藏
 问题点数:0 回复次数:1 
呀!救命呀~~~高手们
有那个高手可以帮我把下面的语言写的登入界面的代码改成用一个类封装起来  然后在用一个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
搜索更多相关主题的帖子: System Text 救命 And 
2008-05-30 22:08
jrs123
Rank: 2
等 级:论坛游民
威 望:1
帖 子:627
专家分:14
注 册:2006-9-5
收藏
得分:0 
走错门了
老兄,你要到这里发帖啊:https://bbs.bccn.net/forum-114-1.html
2008-05-31 11:48
快速回复:呀!救命呀~~~高手们
数据加载中...
 
   



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

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