微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

System.NullReferenceException: '未将对象引用设置为对象的实例怎么修

如何解决System.NullReferenceException: '未将对象引用设置为对象的实例怎么修

我运行代码然后它说 System.NullReferenceException: '未将对象引用设置为对象的实例。'有任何错误。我该怎么办?

Imports MysqL.Data.MysqLClient

Public Class Form1
    Dim gender As String


    Private Sub Form1_Load(sender As Object,e As EventArgs) Handles MyBase.Load
        openCon()
        MsgBox("Connected!")
        con.Close()

    End Sub

    Private Sub rbMale_CheckedChanged(sender As Object,e As EventArgs) Handles rbMale.CheckedChanged
        gender = "Male"
    End Sub

    Private Sub rbFemale_CheckedChanged(sender As Object,e As EventArgs) Handles rbFemale.CheckedChanged
        gender = "Female"
    End Sub

    Private Sub bntOkay_Click(sender As Object,e As EventArgs) Handles bntOkay.Click
        openCon()
        Try
            cmd.Connection = con
            cmd.CommandText = "INSERT INTO tbl_signup (`Full Name`,`Age`,`Gender`,`Birthday`,`Program`) Value('" & txtFullName.Text & "','" & txtAge.Text & "','" & gender & "','" & dtpBirthday.Value.Date & "','" & cbProgram.Selectedindex & "') "
            cmd.ExecuteNonQuery()
            MsgBox("Registered Successfully!")
            con.Close()
            txtFullName.Clear()
            txtAge.Clear()
            rbMale.Checked = False
            rbFemale.Checked = False
            cbProgram.Text = " "

        Catch ex As Exception
            MsgBox(ex.ToString)

        End Try
    End Sub
End Class

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。