“System.NullReferenceException”类型的未经处理的异常在 课程设计__教务管理系统.exe 中发生 其他信息: 未将对象引用设置

qq_24825153 2015-06-07 02:14:57
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_OK.Click
If Username.Text = "" Then
MsgBox("请输入用户名!")
Username.Focus()
Exit Sub
End If
If Password.Text = "" Then
MsgBox("请输入密码!")
Password.Focus()
Exit Sub
End If
Dim icount As Integer
txtSQL = "SELECT * FROM 用户 WHERE 用户名 =‘" & Username.Text & "'"
icount = ExecuteSQL(txtSQL, Errormsg)
If icount = 0 Then
MsgBox("没有此用户,请重新输入用户名!", vbExclamation)
Username.Focus()
Exit Sub

If icount = -1 Then
MsgBox("程序出错!", vbExclamation)
Username.Focus()
Exit Sub
End If
End If
If Trim(Password.Text) = Trim(DBSet.Tables.Item(0).Rows.Item(0).Item("密码").ToString()) Then
username_OK = DBSet.Tables.Item(0).Rows.Item(0).Item("用户名")
frmMain.Show()
Finalize()
Else
MsgBox("密码不正确,请重新输入密码!", vbExclamation)
Password.Focus()
End If

End Sub
...全文
451 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_35508763 2016-07-04
  • 打赏
  • 举报
回复
作为一个c#新手,我在把别人的代码抄到自己程序上面的时候经常碰到这个问题,后来我发现只需要在出错代码处将定义类的顺序换一下就行了,至于原理是啥完全不懂,仁兄可是已经解决了这个问题?弱弱地求指点下
qq_24825153 2015-06-07
  • 打赏
  • 举报
回复
Module Module1 Public username_OK As String Public txtSQL As String Public DBSet As DataSet Public ErrorMsg As String Public Function ExecuteSQL(ByVal strSQL As String, ByRef errMsg As String) As Integer Dim cnn As New SqlClient.SqlConnection Dim cmd As New SqlClient.SqlCommand() Dim adpt As SqlClient.SqlDataAdapter Dim rst As New DataSet() Dim SplitSQL() As String errMsg = "" Try SplitSQL = Split(strSQL) cnn = New SqlClient.SqlConnection(ConnectString()) If InStr("INSERT,DELETE,UPDATE", UCase$(SplitSQL(0))) Then cmd.Connection = cnn cmd.Connection.Open() cmd.CommandText = strSQL ExecuteSQL = cmd.ExecuteNonQuery() Else adpt = New SqlClient.SqlDataAdapter(strSQL, cnn) adpt.Fill(rst) ExecuteSQL = rst.Tables(0).Rows.Count DBSet = rst End If Catch ex As Exception errMsg = ex.Message ExecuteSQL = -1 Finally rst = Nothing cnn = Nothing End Try End Function Public Function ConnectString() As String ConnectString = "Data Source=(local);Initial CataLog=教务管理系统;" End Function Sub main() Dim mf As New login mf.ShowDialog() End Sub End Module 实在是看不出来哪个变量为NULL了,大神们求解救啊

22,206

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧