Information for cut and paste coders
Information for cut and paste coders
Information for cut and paste coders
Information for cut and paste coders
Information for cut and paste coders
Information for cut and paste coders Information for cut and paste coders Information for cut and paste coders Information for cut and paste coders Information for cut and paste coders Information for cut and paste coders Information for cut and paste coders Information for cut and paste coders
Information for cut and paste coders Information for cut and paste coders
Information for cut and paste coders
Go Back  Xtreme Visual Basic Talk > > > Information for cut and paste coders


Reply
 
Thread Tools Display Modes
  #1  
Old 03-22-2013, 11:06 AM
VB_Alien VB_Alien is offline
Senior Contributor
 
Join Date: Apr 2004
Posts: 854
Default Information for cut and paste coders


I just learned a very good lesson today.

I'm not very good at creating database apps, so
i tend to do a lot of web surfing, to find code that
may work in my app.

The thing is, when you do this, the code you borrow
from, usually all use different variables for different
procedures. Lets face it, there really isn't one good
demo app out there that demonstrate all the different
things that can be done with a database, so we borrow
code from many different web sites, to make one
complete app.

Like it said though, all the variables are usually different
and usually, the coder has a lot of trouble getting their
app to work correctly.

When dealing with datasets and datatables and such,
you may run across a piece of code to, lets say, display
records in a datagridview.

The code may use variables like - Dim MyDataset as Dataset,
and that piece of code may work but then you decide that
you want to be able to save the records from the datagridview
and you go searching for more code.

Then ny chance, you do find some and they use a variable
like - Dim ds as Dataset, Dim MyAdapter as Adapter and so
on. Then you find out that that code doesn't work.

Well there is a good reason for that. It's because your not
reusing the same variables that you started with.

If you declare a variable in the declarations area, then
continue using that same variable. If in your declarations,
you create a variable for a dataset(Dim ds as Dataset),
continue using that same variable.

If you find a piece of code the that uses a different variable
for a dataset then change that code to your already declared
variable.

It's best if you put all your initial declarations in the declarations
area like this:

Code:
Dim ds As New DataSet
Dim myCommand As OleDbCommand
Dim myConnection As OleDbConnection
Dim oledbAdapter As OleDbDataAdapter
Dim oledbCmdBuilder As OleDbCommandBuilder

Then later on, if you find a piece of code that - lets say,
is creating a variable for an adapter (Dim MyAdapter as Adapter),
change MyAdapter to oledbAdapter or what-ever you use in
your declaration code.

These are the variables that are suppose to hold all the
database information, all throughout your code. If you change
a variable, then your not going to have any information in it
when you need to use it.
Reply With Quote
  #2  
Old 03-22-2013, 01:25 PM
Gruff's Avatar
GruffInformation for cut and paste coders Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

One should never cut and paste code if you do not understand it. Period.
It is lazy and generally teaches you nothing.

This forum has very strict views on this topic.

It is why we push users to post their code and go to great lengths to explain how and why things work.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Information for cut and paste coders
Information for cut and paste coders
Information for cut and paste coders Information for cut and paste coders
Information for cut and paste coders
Information for cut and paste coders
Information for cut and paste coders Information for cut and paste coders Information for cut and paste coders Information for cut and paste coders Information for cut and paste coders Information for cut and paste coders Information for cut and paste coders
Information for cut and paste coders
Information for cut and paste coders
 
Information for cut and paste coders
Information for cut and paste coders
 
-->