首页 > 解决方案 > vb.net 表单不会启动它只是关闭

问题描述

我将我的第一个表单设置为我的登录页面,但是当我启动它时,它立即关闭

Private Sub login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim ToolTip1 As New ToolTip()
    ToolTip1.AutoPopDelay = 5000
    ToolTip1.InitialDelay = 1000
    ToolTip1.ReshowDelay = 500
    ToolTip1.ShowAlways = True
    ToolTip1.SetToolTip(Me.txt_pword, "Enter password here!")
    ToolTip1.SetToolTip(Me.txt_username, "Enter username here!")
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btn_login2.Click
    dbconn = New SqlConnection
    dbconn.ConnectionString = ("Data Source=JENELIE\SQLEXPRESS;Initial Catalog=LDESfeeding_DB;User ID=sa;Password=Jenelie19")
    Dim reader As SqlDataReader
    Try
        dbconn.Open()
        Dim sql As String
        sql = "select * from auth_pword where Password = '" & txt_pword.Text & "' and username = '" & txt_username.Text & "' "
        dbcomm = New SqlCommand(sql, dbconn)
        reader = dbcomm.ExecuteReader
        Dim ctr As Integer
        ctr = 0
        While reader.Read
            ctr = ctr + 1
        End While
        If ctr = 1 Then
            MessageBox.Show("Login Successful!")
            homepage.Show()
            Me.Close()
        Else
            MessageBox.Show("Incorrect Username or Password!")
        End If
        dbconn.Close()
    Catch ex As SqlException
        MessageBox.Show(ex.Message)
    End Try
End Sub

End Class 这就是这种形式的全部代码。我不知道是什么导致它关闭。我试图将其更改.Close().Hide()仍然没有任何变化。

标签: vb.net

解决方案


推荐阅读