C
CR
I've noticed that the trend these days is to declare variables in the
middle of code instead of at the top. What is the advantage of this?
It seems like it makes it hard to reuse variables.
Here is how all the examples I've seen so far create an OleDbCommand
Object:
Dim cmd as new OleDbCommand("Select * FROM Table1",cnn)
I had to figure out that it was the same as this:
Dim cmd as new OleDbCommand
cmd.CommandText = "SELECT * FROM Table1"
cmd.Connection = cnn
I know it takes 3 lines but at least I know how to reuse it later. How
to you reuse the variable in the first example? I know you could do
this:
'first use
Dim cmd as new OleDbCommand("Select * FROM Table1",cnn)
'second use
cmd.CommandText = "SELECT * FROM Table2"
cmd.Connection = cnn2
But that seems inconsistent, plus I have to figure out which
properties were which in the declaration (CommandText and Connection).
I know I'm being picky but this is bugging me! I'm old school. Or
maybe just old!
Chuck.
middle of code instead of at the top. What is the advantage of this?
It seems like it makes it hard to reuse variables.
Here is how all the examples I've seen so far create an OleDbCommand
Object:
Dim cmd as new OleDbCommand("Select * FROM Table1",cnn)
I had to figure out that it was the same as this:
Dim cmd as new OleDbCommand
cmd.CommandText = "SELECT * FROM Table1"
cmd.Connection = cnn
I know it takes 3 lines but at least I know how to reuse it later. How
to you reuse the variable in the first example? I know you could do
this:
'first use
Dim cmd as new OleDbCommand("Select * FROM Table1",cnn)
'second use
cmd.CommandText = "SELECT * FROM Table2"
cmd.Connection = cnn2
But that seems inconsistent, plus I have to figure out which
properties were which in the declaration (CommandText and Connection).
I know I'm being picky but this is bugging me! I'm old school. Or
maybe just old!
Chuck.