主题:求助,关于VB.NET连接ACCESS设计登录界面的问题
			 luoxin8556
				 [专家分:0]  发布于 2007-07-26 15:26:00
 luoxin8556
				 [专家分:0]  发布于 2007-07-26 15:26:00							
			想设计一个登录界面,界面设置如图一样,求助如何连接ACCESS数据库,当点击确定时,通过验证数据库内的用户名和密码是否一致,然后允许登入,具体连接数据库的代码我一直搞不明白。
[img]http://photo.store.qq.com/http_imgload.cgi?/rurl2=e9e8d62f09207a8757a48d20407a56a9c71176ff0692c019c25fffe4f2166bf9884b92ac1eed7304e3df39101ff38bcc6b40b322f87cd25b2792bb88609d2b9b0a59729eed8a2be79229a5a85466ced2a879a7af[/img]
			最后更新于:2007-07-26 15:29:00
			
					 
		
			
回复列表 (共2个回复)
		
								
				沙发
				
					 jzyray [专家分:20610]  发布于 2007-07-26 23:52:00
jzyray [专家分:20610]  发布于 2007-07-26 23:52:00				
				建议看一下ADO.NET及SQL语句的相关知识
							 
						
				板凳
				
					 zhu314746943 [专家分:0]  发布于 2009-09-29 17:05:00
zhu314746943 [专家分:0]  发布于 2009-09-29 17:05:00				
				
Imports System.IO
Imports System.Data
Imports System.Data.OleDb
Public Class form1
    Inherits System.Windows.Forms.Form
    Dim mycommand As OleDbCommand
    Dim mydatareader As OleDbDataReader
    Private Sub Txt_Username_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Txt_Username.LostFocus
        If Txt_Username.Text = "" Then
            MsgBox("请输入用户名", MsgBoxStyle.Information, "警告")
            Exit Sub
        End If
    End Sub
    Private Sub btn_ok_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_ok.Click
        Dim path As String = Directory.GetCurrentDirectory()
        If Txt_Username.Text = "" Then
            MsgBox("请输入用户名", MsgBoxStyle.Information, "警告")
            Exit Sub
        ElseIf Txt_pwd.Text = "" Then
            MsgBox("请输入密码", MsgBoxStyle.Information, "警告")
            Exit Sub
        End If
        Dim myconnection As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=" & Application.StartupPath & "\student0.mdb")
        myconnection.Open()
        Dim s As String = "select * from 管理员表 where username='" & Trim(Txt_Username.Text).Replace("'", "''") & "' and password='" & Trim(Txt_pwd.Text).Replace("'", "''") & "'"
        'If myconnection.State = ConnectionState.Closed Then myconnection.Open()
        mycommand = New OleDbCommand(s, myconnection)
        mydatareader = mycommand.ExecuteReader()
   
        If mydatareader.Read = False Then
            MsgBox("用户名不存在或者密码错误", 0 + 48, "提示")
        Else
            Me.Hide()
            Form2.Show()
        End If
        mydatareader.Close()
        myconnection.Close()
    End Sub
    Private Sub btn_cancel_Click1(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_cancel.Click
        End '或是Application.Exit()
    End Sub
    Private Sub LoginFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.CenterToScreen()
    End Sub
End Class
							 
									
			
我来回复