| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 593 人关注过本帖
标题:登录界面连接数据库问题
只看楼主 加入收藏
yulphoenix
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2005-10-27
收藏
 问题点数:0 回复次数:0 
登录界面连接数据库问题

我也做了一个登录界面!数据库是用ACCESS做的一个userID表!
代码如下:
Imports System.Data
Imports System.Data.oledb
Public Class Frmlogin
Inherits System.Windows.Forms.Form
Public adocmd As oledbDataAdapter
Public ds As DataSet = New DataSet
Public mytable As Data.DataTable
Public myrow As Data.DataRow
Public rownumber As Integer
Public searchsql As String
Public cmd As oledbCommandBuilder
Private Sub BtnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOK.Click
Try
Me.Text = "正在验证...."
Me.Cursor = System.Windows.Forms.Cursors.WaitCursor
Dim tablename As String
tablename = "userID"
searchsql = "select 用户名,密码 from userID where(用户名='" & Txtusername.Text & " ')"

Executesql(searchsql, tablename)
If myrow.Item(1) = txtuserpassword.text Then

Dim newfrmmain As New Frmmain
newfrmmain.Show()
Me.Hide()
Else
MsgBox("密码错误")
Txtuserpassword.Text = ""
Me.Text = ""
Me.Cursor = System.Windows.Forms.Cursors.Arrow
Txtuserpassword.Focus()


End If

Catch ex As Exception
MsgBox("用户名不存在!", MsgBoxStyle.OKOnly, "提示")
Txtusername.Text = ""
Txtuserpassword.Text = ""
Me.Text = ""
Me.Cursor = System.Windows.Forms.Cursors.Arrow


End Try
End Sub

Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
Me.Dispose()
End Sub
Public Function Executesql(ByVal sql As String, ByVal table As String)
adocmd = New OleDbDataAdapter(sql, "provider=microsoft .jet.oledb.4.0;data source=c:\student")
adocmd.Fill(ds, table)
mytable = ds.Tables.Item(0)
rownumber = 0
myrow = mytable.Rows.Item(rownumber)

End Function
End Class
可以运行,但是无论我输入什么都是提示“用户名不存在”,大家帮忙看看哪出错了。

搜索更多相关主题的帖子: 数据库 界面 登录 
2006-05-05 12:36
快速回复:登录界面连接数据库问题
数据加载中...
 
   



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

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