How do I get my new form inmediately after form2.showdialog()?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alfredo73
    New Member
    • Feb 2009
    • 12

    How do I get my new form inmediately after form2.showdialog()?

    Hi,

    I am writing an application in VB2008 with several forms. From Form1 I open a new form with me.hide() and then form2.showdialo g(). The system works but in form2 the application runs without screendisplay until the program waits for a user input. So first all databases are processed. Meanwhile no screen is visible for the user. Sometimes this takes about 5 seconds. I would like the user to see the build up screen directly. How can I improve this ?
  • OuTCasT
    Contributor
    • Jan 2008
    • 374

    #2
    How have u bound ur database to the program ?

    Comment

    • Alfredo73
      New Member
      • Feb 2009
      • 12

      #3
      It is connected by:

      Public connectionstrin g As String = "Data Source=.\SQLEXP RESS;AttachDBFi lename=d:\datab ases\dtbs.mdf;I ntegrated Security=True;C onnect Timeout=30;User Instance=True"
      Public myconnection As New SqlConnection(c onnectionstring )
      Public sqlcommando As New SqlCommand()

      and in the sub:
      sqlcommando.Con nection = myconnection
      sqlcommando.Com mandText = "SELECT * FROM Accounts where AccountNr = '" + AccountNrTextBo x.Text + "'"
      myconnection.Op en()
      Dim myReader As SqlDataReader
      myReader = sqlcommando.Exe cuteReader()

      Comment

      • OuTCasT
        Contributor
        • Jan 2008
        • 374

        #4
        So u are saying that when u click to on a button to show form2 like form2.show and u hide the form1 with me.hide. Then the connection is executed and then it take like 5 seconds to load the form2 where the information from the database will be displayed ?

        Comment

        • Alfredo73
          New Member
          • Feb 2009
          • 12

          #5
          Hi OuTCasT, thanks for your reply. Yes, when the program executes Form2 and even if the first line of the load_form2 says label1.text="Wh atever", it first executes all other commands (which takes up to 5 seconds) before it shows Form2. (might it be any setting that says dont show the form before everything is finished?)

          Comment

          • OuTCasT
            Contributor
            • Jan 2008
            • 374

            #6
            How have u bound ur data to your controls on the Form2 ??
            Like the textboxes etc ?

            It would be better to fill a dataset with the data instead of loading it straight to the form and then editing the dataset with the information you need and submitting the changed dataset back to the database

            Comment

            • Alfredo73
              New Member
              • Feb 2009
              • 12

              #7
              No, nothing is bound in the design. In the class I give the orders like label1.text=myr eader("AccountN r"). The tables are small (only 10 lines at the moment), 4 tables in the database.

              Comment

              • OuTCasT
                Contributor
                • Jan 2008
                • 374

                #8
                Code:
                Dim sqlcon As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=pd;Integrated Security=True")
                    'Commands and adapter for the Employee masterfile
                    Dim sqlEmployeeCommand As SqlCommand
                    Dim sqlEmployeeAdapter As SqlDataAdapter
                    Dim sqlEmployeeDataTable As DataTable
                    'Currency Managers for Commands above
                    Dim sqlEmployeeManager As CurrencyManager
                
                'lblPaymentPeriod.Text = strPaymentPeriod
                        sqlEmployeeCommand = New SqlCommand("SELECT * FROM EmployeeDetails order by EmployeeID", sqlcon)
                        sqlEmployeeAdapter = New SqlDataAdapter(sqlEmployeeCommand)
                        sqlEmployeeDataTable = New DataTable
                        sqlEmployeeAdapter.Fill(sqlEmployeeDataTable)
                
                ' Fill Table with EmployeeDetails
                        lblInitials1.DataBindings.Add("text", sqlEmployeeDataTable, "Employeeinitials", True)
                        lblEmployeeName1.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeSurname", True)
                        lblPaymentPeriod.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeePaymentType", True)
                        ' lblEmployeePreviousNormalStatus.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeePreviousNormalStatus", True)
                        txtEmployeeCode.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeID", True)
                        txtSurname.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeSurname", True)
                        txtInitials.DataBindings.Add("Text", sqlEmployeeDataTable, "EmployeeInitials", True)
                        txtFirstNames.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeFirstName", True)
                        cbTitle.DataBindings.Add("SelectedItem", sqlEmployeeDataTable, "EmployeeTitle", True)
                        txtNickName.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeNickName", True)
                        txtPhysAddress1.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeePhysicalAddress1", True)
                        txtPhysAddress2.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeePhysicalAddress2", True)
                        txtPhysAddress3.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeePhysicalAddress3", True)
                        txtPhysPCode.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeePhysicalPostalCode", True)
                        cbGroup.DataBindings.Add("SelectedItem", sqlEmployeeDataTable, "EmployeeGroup", True)
                        cbGender.DataBindings.Add("SelectedItem", sqlEmployeeDataTable, "EmployeeGender", True)
                        cbLanguage.DataBindings.Add("SelectedItem", sqlEmployeeDataTable, "EmployeeLanguage", True)
                        cbMaritalStatus.DataBindings.Add("SelectedItem", sqlEmployeeDataTable, "EmployeeMaritalStatus", True)
                        txtTelHome.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeTelHome", True)
                        txtCellNo.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeCellNo", True)
                        txtTelWork.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeTelWork", True)
                        txtWorkExt.DataBindings.Add("text", sqlEmployeeDataTable, "employeeWorkExt", True)
                        txtRoomNo.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeRoomNo", True)
                        txtEmailAddress.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeEmailAddress", True)
                        txtPostalAdd1.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeePostalAddress1", True)
                        txtPostalAdd2.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeePostalAddress2", True)
                        txtPostalAdd3.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeePostalAddress3", True)
                        txtPCode.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeePostalCode", True)
                        txtID.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeIdNumber", True)
                        txtPassport.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeePassportNumber", True)
                        cbNature.DataBindings.Add("SelectedItem", sqlEmployeeDataTable, "EmployeeNature", True)
                        txtTaxNo.DataBindings.Add("text", sqlEmployeeDataTable, "EmployeeTaxNumber", True)
                        cbEmployeeUifCountry.DataBindings.Add("SelectedItem", sqlEmployeeDataTable, "EmployeeUifCountry", True)
                        sqlEmployeeManager = DirectCast(Me.BindingContext(sqlEmployeeDataTable), CurrencyManager)
                This will work much faster.

                Comment

                • Alfredo73
                  New Member
                  • Feb 2009
                  • 12

                  #9
                  Thanks, I am gonna try it and will come back to U.

                  Comment

                  • OuTCasT
                    Contributor
                    • Jan 2008
                    • 374

                    #10
                    Let me knw if it worked for you. I have alot of records in my database and this method is pretty fast.

                    I can show u how to navigate through the rows and to update the database with the new dataset when ur done.

                    Comment

                    Working...