Disadvantage of form created objects.

I am trying to learn "The right way" of programming in VB.NET. What I have noticed in the tutorials at Microsoft or LearnVisualStudio.com is that most of the time they drag the objects to the form from the toolbar, such as grids, dataadapters, etc.

Now when on the forums and I ask questions, the code returned from the responding party normally has things created in code such as this.

Dim connection As SqlConnection = New SqlConnection("Secret text in here")
Dim command As SqlCommand = New SqlCommand("RETURNIT", connection)
Dim adapter As SqlDataAdapter = New SqlDataAdapter(command)
Dim table As DataTable = New DataTable
I want to learn the "right way" or even the way that will make my program cleaner and faster, whatever the best practice is.
Who is Participating?
"But the form seems to generate much code that is not really needed right ? Does this slow things down greatly ?"  

No, the performance is not affected at all. (what's a few micro-seconds, here or there, amongst friends???  LOL)

I think it is more of a thing of 6 in one half dozen in the other. Probably you should just pick what is the quickest for you to perform. Some people write code faster than they can pop into the form designer and set the properties.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Right...also when answering questions for other people, it sometimes easier to create everything in code so that you don't have to worry about what the name of the control on question askers Form is...
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

reefcrazedAuthor Commented:
But the form seems to generate much code that is not really needed right ? Does this slow things down greatly ?
I believe the points should be split between Arthur_Wood, Idle_Minds and Myself. We have all contributed to answering his question.
I agree
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.