请大家帮我解决一个vb.net的问题,谢谢

作者在 2010-04-16 15:56:37 发布以下内容
大家好,我在做vb.net编程时,出现了这样一个问题,不知道该怎么办,我是学生,是新手,请懂的人帮帮我,谢谢了!!!
 
未处理的“System.InvalidOperationException”类型的异常出现在 w.exe 中。

其他信息: 创建窗体时出错。有关详细信息,请参阅 Exception.InnerException。错误为: 未将对象引用设置到对象的实例。
界面log1代码如下:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlConnection
Imports System.Data.SqlClient.SqlDataReader
Public Class log1
    Inherits System.Windows.Forms.Form

    Dim myreader = SqlCommand1.ExecuteReader()

    Function user() As Boolean
        SqlConnection1.Open()
        SqlCommand1 = New SqlCommand("SELECT * FROM 用户信息 WHERE 用户名= '" & TextBox1.Text & "'", SqlConnection1)
        myreader = SqlCommand1.ExecuteReader()
        Dim TempString As String
        Dim type As String
        While myreader.Read
            TempString = myreader("用户密码")
            type = myreader("用户类型")
        End While
        SqlConnection1.Close()
        myreader.Close()
        SqlCommand1.Dispose()
        If TextBox2.Text = TempString And ComboBox1.Text = type Then
            Return True
        Else
            If TextBox2.Text <> TempString And ComboBox1.Text <> type Then
                Return False
            End If
        End If
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim main As New Form()
        If TextBox1.Text = "" Or TextBox2.Text = "" Or ComboBox1.Text = "" Then
            MsgBox("请输入相应信息!", MsgBoxStyle.Information, "超市管理系统")

        ElseIf TextBox1.Text <> "" And TextBox2.Text <> "" And ComboBox1.Text <> "" And user() = True Then
            main.Show()
        Else
            MsgBox("密码不正确或管理员信息不匹配!")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub



界面 main代码如下:
Public Class main
    Inherits System.Windows.Forms.Form


    Private Sub ToolStripLabel6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel6.Click

    End Sub

    Private Sub ToolStripLabel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel1.Click
        Dim log1 As New Form()
        log1.Show()
        Me.Close()

    End Sub

    Private Sub ToolStripLabel2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel2.Click
        用户管理.Show()
    End Sub

    Private Sub ToolStripLabel4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel4.Click
        入库.show()
    End Sub

    Private Sub ToolStripLabel3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel3.Click
        出库.show()
    End Sub

    Private Sub ToolStripLabel5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel5.Click
        查询.show()
    End Sub

    Private Sub ToolStripLabel7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel7.Click
        关于.show()
    End Sub

    Private Sub ToolStripLabel8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel8.Click
        End
    End Sub

    Private Sub main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If log1.ComboBox1.Text = "普通员工" Then
            ToolStripLabel2.Enabled = False
            ToolStripLabel3.Enabled = False
            ToolStripLabel4.Enabled = False
            用户报表ToolStripMenuItem.Enabled = False
        End If
        If log1.ComboBox1.Text = "普通管理员" Then
            ToolStripLabel2.Enabled = False
            用户报表ToolStripMenuItem.Enabled = False
        End If
  
    End Sub


End Class
默认分类 | 阅读 518 次
文章评论,共0条
游客请输入验证码
文章分类
文章归档
最新评论