What is the best hand coded way to display date from the database into textboxes?

emaduddeen

Well-known member
Joined
May 5, 2010
Messages
171
Location
Lowell, MA & Occasionally Indonesia
Programming Experience
Beginner
Hi Everyone,

Can you tell me what is the best hand coded way to display data from the database into textboxes?

Currently I'm using a data adapter, data set, with a parameter. After I fill the dataset, I load the data into the textboxes using this code as an example:

VB.NET:
                    editBoxFirstName.Text = _
                        objDataSetCustomerDetails.Tables("Customer Details").Rows(0) _
                        .Item("FirstName").ToString

                    EditBoxLastName.Text = _
                        objDataSetCustomerDetails.Tables("Customer Details").Rows(0) _
                        .Item("LastName").ToString

       ... plus all the other textboxes.

When the program is running this process take about 7 seconds to complete before the data is shown on the form so I know this way of doing things is not efficient.

When it's time to save the data to the database, there is no big delay in time. It's only when loading it into the textboxes.

Thanks.

Truly,
Emad
 
Are you only getting one row? Have you tested to see what actual part of the code taking the time? You should be using the Stopwatch class for that. Also, what exactly do you mean by "hand-coded"?
 
Hi,

Thanks for the reply.

Yes, the code gets 1 row from the dataset.

I did not test it yet. I will look up how to user the stopwatch to see which statement is slow.

By hand coding I am not using the wizard to create the dataset, data adapter, etc. because they are created by vb code statements.

Truly,
Emad
 
Hi.

It was not the loading of the textboxes that was slowing it down. It was the call to InitializeComponent().

Is there any way to make it faster?

VB.NET:
        Dim stpWatchInfo As New System.Diagnostics.Stopwatch

        MsgBox("Press OK when you are ready to see the time elapsed in seconds")

        stpWatchInfo.Start()

        ' This call is required by the designer.
        '---------------------------------------
        InitializeComponent()

        stpWatchInfo.Stop()

        MsgBox("Elapsed Time in Seconds is: " & stpWatchInfo.Elapsed.Seconds)

Truly,
Emad
 
The contents of InitializeComponent is generated by the designer based on what you do visually. Given that we have no idea what it contains, there's no way that we can suggest a way to speed it up.
 
Hi,

Thanks for the reply.

Since I was using the new sub procedure to pass a parameter to the form, I think I may try using a global for the parameter and not use the new sub procedure and move all the code into the forms load event and see if it gets displayed quicker.

Truly,
Emad
 
Back
Top