Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15543

VS 2019 StackOverflorException on closing form

$
0
0
Good Afternoon All,

I'm hoping that someone can assist me with this one as I'm struggling.

I have the following code on a form to display and update a datagridview with data from a MySQL Database.

Code:

Public Class RadfrmEmailNotifications
    Private MySQLBS As New BindingSource
    Private MySQLDT As New DataTable
    Private MySQLDA As MySqlDataAdapter

    Private Sub RadfrmEmailNotifications_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.FormElement.TitleBar.RightToLeft = False
        Me.MdiParent = RibfrmMain

        gridviewEmailNotifications.DataSource = MySQLBS
        GetData("SELECT tblemail_anouncement_users.urn AS 'User ID', tblemail_anouncement_users.first_name AS 'Users First Name', tblemail_anouncement_users.surname AS 'Users Surname', tblemail_anouncement_users.email AS 'Users Email' FROM tblemail_anouncement_users ORDER BY tblemail_anouncement_users.surname ASC;")
        gridviewEmailNotifications.BestFitColumns()
        gridviewEmailNotifications.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
        gridviewEmailNotifications.Focus()
    End Sub

    Private Sub GetData(ByVal selectCommand As String)
        MySQLDA = New MySqlDataAdapter(selectCommand, strDBConnectionString)
        Dim commandBuilder As MySqlCommandBuilder = New MySqlCommandBuilder(MySQLDA)
        Dim table As DataTable = New DataTable With {
            .Locale = CultureInfo.InvariantCulture
        }
        MySQLDA.Fill(table)
        MySQLBS.DataSource = table
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        MySQLDA.Update(CType(MySQLBS.DataSource, DataTable))
        GetData(MySQLDA.SelectCommand.CommandText)
        btnSave.Enabled = False
    End Sub

    Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
        GetData(MySQLDA.SelectCommand.CommandText)
    End Sub

    Private Sub gridviewEmailNotifications_CellValueChanged(sender As Object, e As GridViewCellEventArgs) Handles gridviewEmailNotifications.CellValueChanged
        btnSave.Enabled = True
    End Sub

    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click, MyBase.FormClosing
        If btnSave.Enabled = True Then
            RadMessageBox.SetThemeName("CrystalDark")
            Dim radmsgbox As DialogResult = RadMessageBox.Show("Changes have been made to this list but have not been saved." & vbCrLf & "" & vbCrLf &
                                                              "Would you like to save these changes before closing this window?", "", MessageBoxButtons.YesNo, RadMessageIcon.Question)
            If radmsgbox = DialogResult.Yes Then
                MySQLDA.Update(CType(MySQLBS.DataSource, DataTable))
            End If
        Else
            Me.Close()
        End If
    End Sub



Everything is working perfectly with the DataGridView however when I try and close the form I am getting the below error on the
Code:

Me.Close
line.

System.StackOverflowException
HResult=0x800703E9
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>

I have been looking online for further information on this however it is all referring to an infinite loop however I can't seem to see where this loop is as I haven't written one in. I'm wondering if it could be related to the datagridview and the data sync however I don't know enough about how these work to determine if this is te cause.

Can someone please assist me with it.

Thanks in advanced

Luke

Viewing all articles
Browse latest Browse all 15543

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>