我做个登陆窗口,可有一个问题解决不了,望高人指点,不胜感激啊
原码如下:
Public Class frmlogin
Inherits System.Windows.Forms.Form
Public bresult As Boolean = False
Public userid As String = ""
Public username As String = ""
Public userpwd As String = ""
Private Sub txbpwd_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txbpwd.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) And userid <> "" Then
Me.btnsubmit_Click(Nothing, Nothing)
End If
End Sub
Private Sub txbuserid_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txbuserid.KeyPress
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
Me.txbpwd.Focus()
End If
End Sub
Private Sub txbuserid_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txbuserid.LostFocus
Dim db As DataBase = New DataBase
Dim dv As DataView = db.RunDelOrInsSQL(" select 密码,用户名 from 用户表 where 用户号='" + Me.txbuserid.Text.Trim() + "'")
If dv.Count = 0 Then
Me.txbuserid.Text = ""
Me.txbpwd.Text = ""
Me.txbname.Text = ""
Else
userid = Me.txbuserid.Text.Trim()
Me.userpwd = dv.Item(0)("密码")
Me.txbname.Text = dv.Item(0)("用户名")
End If
db.Dispose()
End Sub
Private Sub btnsubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
If Me.userpwd.Trim() = Me.txbpwd.Text.Trim() And userpwd <> "" Then
bresult = True
username = Me.txbname.Text.Trim()
Me.Close()
Else
bresult = False
MessageBox.Show("请确认你的用户名或密码是否正确!!")
End If
End Sub
Private Sub btnclear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnclear.Click
Me.Close()
Application.Exit()
End Sub
End Class
=================================================================================================================================
==================================================================================================================================
====================================================================================
可是执行时却有如下错误:
未处理的“System.NullReferenceException”类型的异常出现在 财务管理.exe 中。
其他信息: 未将对象引用设置到对象的实例。
-----------------------------------------------
---------------------------------------------
--------------------------------------
Private Sub txbuserid_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txbuserid.LostFocus
Dim db As DataBase = New DataBase
Dim dv As DataView = db.RunDelOrInsSQL(" select 密码,用户名 from 用户表 where 用户号='" + Me.txbuserid.Text.Trim() + "'")
If dv.Count = 0 Then
Me.txbuserid.Text = ""
Me.txbpwd.Text = ""
Me.txbname.Text = ""
Else
userid = Me.txbuserid.Text.Trim()
Me.userpwd = dv.Item(0)("密码")
Me.txbname.Text = dv.Item(0)("用户名")
End If
db.Dispose()
End Sub
其中划横线的地方背景颜色为黄(调试时).
=================================================================================================================
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
==================================================================================================================
上述问题该怎么处理啊,是什么原因导致的?谢谢,请教高手.