你调用的对象是空的。 vb.net在向mysql插入数据时

时间:2017-08-07 12:41:07

标签: mysql vb.net

我正在尝试在我的数据库中插入数据tbl_admin,我收到了这样的错误:

MysqlConn = New MySqlConnection
    MysqlConn.ConnectionString = "server=localhost;userid=root;password=;database=vbdb"
    Try
        MysqlConn.Open()
        COMMAND.Connection = MysqlConn 
        COMMAND.CommandType = CommandType.Text
        COMMAND.CommandText = "INSERT INTO vbdb.tbl_admin (LastName, FirstName, MiddleName, UserName, Admin_Password) VALUES (@lName,@fName,@mName,@username,@password)"
        COMMAND.Parameters.AddWithValue("@lName", stflname.Text)
        COMMAND.Parameters.AddWithValue("@fName", stffname.Text)
        COMMAND.Parameters.AddWithValue("@mName", stfmiddlename.Text)
        COMMAND.Parameters.AddWithValue("@username", stfusername.Text)
        COMMAND.Parameters.AddWithValue("@password", stfpassword.Text)
        COMMAND.ExecuteNonQuery()
        MsgBox("New Employee Data Saved")
        clearFields()

        MysqlConn.Close()


    Catch ex As Exception
        MysqlConn.Close()

        MessageBox.Show(ex.Message)

    Finally
        MysqlConn.Dispose()
    End Try

0 个答案:

没有答案