| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1309 人关注过本帖
标题:用户登陆问题求助
取消只看楼主 加入收藏
wangkq936
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2008-4-18
收藏
 问题点数:0 回复次数:4 
用户登陆问题求助
本人学习学做一个登陆窗体,运行时提示用户名或密码错,请大家帮我看下是哪个地方写错了,以下是原码:
Public Class Form3
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cnStr As String, cmdtext As String
        cnStr = "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath() & "\database.mdb"
        Dim cn As New OleDbConnection(cnStr)
        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader
        Dim dt As New DataTable("user")
        Try
            cn.Open()
            cmdtext = "select * from user where name='" & nametext.Text & "' and password='" & pwtext.Text & "'"
            cmd = New OleDbCommand(cmdtext, cn)
            dr = cmd.ExecuteReader
            If dr.HasRows Then
                MessageBox.Show("登陆成功", "系统登陆", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                dr.Close()
            End If

        Catch ex As Exception
            MessageBox.Show("用户名或密码错误", "系统登陆", MessageBoxButtons.OK, MessageBoxIcon.Information)
            nametext.Text = Nothing
            pwtext.Text = Nothing
            nametext.Focus()

        Finally
            cn.Close()
            cn = Nothing
        End Try
    End Sub
搜索更多相关主题的帖子: 用户 登陆 
2008-11-26 10:50
wangkq936
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2008-4-18
收藏
得分:0 
论坛太够意思了,发了这么久都没有人回应下,管理员去哪里了?该罚了!
2008-12-08 13:36
wangkq936
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2008-4-18
收藏
得分:0 
请问楼上,你是用VS什么版本来试的,我用2005/2008都试过了结果还是一样,能不能把试好没有总是的原代码发给我,我调了很久都没有搞定,我的邮箱是wangkq-936@,谢谢你了,论坛就是用来学习交流的是吗!
2008-12-09 11:52
wangkq936
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2008-4-18
收藏
得分:0 
搞定了,谢谢你的帮助,
2008-12-16 15:23
wangkq936
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2008-4-18
收藏
得分:0 
楼主 wangkq936 的帖子
跟大家一起分享登陆问题的,VS2005下调试正常的代码:
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

        Dim cnStr As String, cmdtext As String
        cnStr = "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath() & "\database.mdb"
        Dim cn As New OleDb.OleDbConnection(cnStr)
        Dim cmd As OleDb.OleDbCommand
        Dim dr As OleDb.OleDbDataReader
        Dim dt As New DataTable("userInfo")
        Try
            cn.Open()
            cmdtext = "select * from userInfo where name = '" & txtName.Text.ToString() & "' and password = '" & txtPassword.Text.ToString() & "'"
            cmd = New OleDb.OleDbCommand(cmdtext, cn)
            dr = cmd.ExecuteReader
            If dr.HasRows Then
                MessageBox.Show("登陆成功", "系统登陆", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("用户名或密码错误", "系统登陆", MessageBoxButtons.OK, MessageBoxIcon.Information)
                txtName.Text = Nothing
                txtPassword.Text = Nothing
                txtName.Focus()
            End If
        Catch ex As Exception
             MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            cn.Close()
            cn = Nothing
        End Try
2008-12-16 15:37
快速回复:用户登陆问题求助
数据加载中...
 
   



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

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