Question My DatetimePicker (to find Date Interval) stuck my form and the whole program..

addy_yuki

New member
Joined
Apr 16, 2010
Messages
2
Programming Experience
Beginner
hye there..,i am using Visual Studio 2008 and VB.NET 2008 and SQL Server 2005 as the database. I just finished designing & writing codes for a customer's contract information and , however after it has been connected to the database only one of the datetimepicker can be click, (i put 2 datetimepickers to find date interval) and the rest of the function including in the form are not working! it seems that the form stuck and NOT responding. i cant even close the form using the X button, so i have to stop the process using compiler (visual studio 2008), however if i press the 'Delete' button before the 'Add' button, it will successfully delete the data.. but if i disconnected the form from the database, (disabled the form_load codes [put 'quote']) the both of datetimepicker will work and able to view the date interval (after pressing the 'Calculate Period' button) in addition how to make it appear automatically in screen without using the button? below are the code, I try to make some other form.. but it is still the same
VB.NET:
Imports System.Data.SqlClient
Imports System
Imports System.Data
Imports System.Windows.Forms.DataGridView

Public Class Cust_info
    Dim SqlConnection As New SqlClient.SqlConnection
    Dim monthsTotal As Integer



    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim SqlConnection As New SqlClient.SqlConnection
        SqlConnection.ConnectionString = "Data Source=ADDYADNAN-PC\SQLEXPRESS;Initial Catalog=CBTS;Integrated Security=True"
        'TODO: This line of code loads data into the 'CBTSDataSet.customer_info' table. You can move, or remove it, as needed.
        Me.Customer_infoTableAdapter.Fill(Me.CBTSDataSet.customer_info)
        Me.BringToFront()
        Me.Show()
        c_Id_Text.Enabled = False
        c_Name_Text.Enabled = False
        DateTimePickerStart.Enabled = False
        DateTimePickerEnd.Enabled = False
        con_amnt.Enabled = False
        con_period.Enabled = False
        payMethod.Enabled = False

    End Sub

    Private Sub AddCustBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddCustBtn.Click
        Me.CustomerinfoBindingSource.AddNew()

        c_Id_Text.Enabled = True
        c_Name_Text.Enabled = True
        DateTimePickerStart.Enabled = True
        DateTimePickerEnd.Enabled = True
        con_amnt.Enabled = True
        con_period.Enabled = True
        payMethod.Enabled = True
    End Sub
    Private Sub delCustInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delCustInfo.Click
        Me.CustomerinfoBindingSource.RemoveCurrent()

        c_Id_Text.Enabled = True
        c_Name_Text.Enabled = True
        DateTimePickerStart.Enabled = True
        DateTimePickerEnd.Enabled = True
        con_amnt.Enabled = True
        con_period.Enabled = True
        payMethod.Enabled = True
    End Sub

    Private Sub reset1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles reset1.Click
        c_Id_Text.Clear()
        c_Name_Text.Clear()
        DateTimePickerStart.ResetText()
        DateTimePickerEnd.ResetText()
        con_amnt.Clear()
        con_period.Clear()
        Pay_method.ResetText()

    End Sub

    Private Sub ExitCustInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitCustInfo.Click
        ExitDialog.BringToFront()
        ExitDialog.Activate()
        ExitDialog.Show()
    End Sub

    Private Sub back2menu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles back2menu.Click
        Me.Hide()
        FrontPage.BringToFront()
        FrontPage.Activate()
        FrontPage.Show()
    End Sub
    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)

    End Sub

   Private Sub DateTimePickerStart_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePickerStart.ValueChanged

    End Sub
    Private Sub DateTimePickerEnd_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePickerEnd.ValueChanged
       
    End Sub

    Private Sub ButCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButCalc.Click
        Dim Con_Start1 As Date = DateTimePickerStart.Value
        Dim con_end1 As Date = DateTimePickerEnd.Value

        monthsTotal = DateDiff(DateInterval.Month, Con_Start1, con_end1)

        Me.con_period.Text = monthsTotal

    End Sub

    Private Sub c_Id_Text_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles c_Id_Text.TextChanged

    End Sub

    Private Sub c_Name_Text_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles c_Name_Text.TextChanged

    End Sub

    Private Sub con_amnt_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles con_amnt.TextChanged

    End Sub

    Private Sub con_period_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles con_period.TextChanged

    End Sub

    Private Sub Pay_method_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Pay_method.SelectedIndexChanged

    End Sub

    Private Sub DataGridView1_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub
   
    Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePickerEnd.ValueChanged

    End Sub

  
    Private Sub updateBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updateBtn.Click
        Me.Validate()
        Me.CustomerinfoBindingSource.EndEdit()
        Me.Customer_infoTableAdapter.Update(Me.CBTSDataSet.customer_info)
        MessageBox.Show("Data has been Updated")
    End Sub
End Class
 
The most likely explanation for that sort of thing is that you have entered an endless loop. Have you actually checked what's happening in code? When you enter that state, click the Break All button in VS and it will stop executing wherever it is. You can then step through the code line by line to see what's happening. If the code won't step then it's probably waiting for a function to return that isn't, so that would be the issue.
 
hurmmmm.... unfortunately i dont really understand the concept of loop..since im still new in programming. lol..if possible, could you help me to fix a bit with my code...at least tell me which part that should I alter. :)
 
I have no idea what part you should alter. It's up to you to work that out by doing what I suggested.

What does the term "loop" mean to you? It's something that goes round and round the same path over and over, right? It should be fairly obvious how that applies to code. If you step through your code and it keeps going over the same part(s) over and over then you're in an infinite loop. It could be something like you're handling the TextChanged event of two different TextBoxes and, in each event handler, you change the Text of the other control. That would keep raising the two events over and over: infinite loop.

At the very least you can use the Break All button to find out where your code is at when the issue occurs. Should should then be able to use F10 to step line by line to see if you do indeed end up in an infinite loop.
 
Back
Top