标题:新人一个,请求帮忙,有关链接数据库的问题。
取消只看楼主
屎宝宝
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2012-3-19
结帖率:66.67%
 问题点数:0 回复次数:2 
新人一个,请求帮忙,有关链接数据库的问题。
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim conn As New SqlClient.SqlConnection
        conn.ConnectionString = "server=DELL PC;uid=sa;pwd=sql;database=gg_user   "
        conn.Open()
        Dim cmd As New SqlClient.SqlCommand
        cmd.Connection = conn
         = "select * from login where user_id='" & Me.txtuser_id.Text & "' and user_pwd=" & Me.txtpassword.Text & " "
        Dim dr As SqlClient.SqlDataReader
        dr = cmd.ExecuteReader
        If dr.Read Then
            If dr!user_state = "停用" Then
                MsgBox("用户已停用!!!")
            End If
            If txtuser_id.Text = dr.Item("user_id") And txtpassword.Text = dr.Item("user_pwd") Then
                MsgBox("登陆成功!")
                Me.Hide()
                Dim form2 As New Form2
                form2.Show()
            End If

        Else
            MsgBox("请输入正确的用户名和密码或用户不存在!!", MsgBoxStyle.Critical)
        End If
        dr.Close()
        conn.Close()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub

    Private Sub txtname_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtuser_id.KeyPress
        If e.KeyChar = Chr(13) Then
            txtpassword.Focus()
            txtpassword.SelectAll()
        End If
    End Sub

    Private Sub txtpassword_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtpassword.KeyPress
        If e.KeyChar = Chr(13) Then
            Button1.Focus()
        End If
    End Sub
End Class
搜索更多相关主题的帖子: 数据库 sql database server where 
2012-11-17 23:43
屎宝宝
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2012-3-19
得分:0 
为什么链接不到数据库啊???啥原因啊???
2012-11-18 17:18
屎宝宝
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2012-3-19
得分:0 
回复 4楼 jianjunfeng
谢了
2012-11-20 11:03



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




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

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