I have just turned on option strict in ASP/VB.net. I started by happily
going through and setting up all of the Dim statements with As clauses, and
making my cast explicit. However, I have now got stuck on "late binding".
After reading that early binding is faster, I think that it would be best to
make everything early binding, but I can't work out how. have but a sample
of my database code below. Can anyone tell me how to fix it?
Thanks,
Martin
Public Sub aSub()
'Allocate Variables
Dim adCmdText, aConnectionString, SQL As String
Dim R, F, RecsAffected As Object
Dim conn As Object
'set connection string for login to database
aConnectionString = "Provider=SQLOLEDB;Data Source=server;" _
& "Database=aDataBase;UID=aUserID;PWD=aPassword"
conn = Server.CreateObject("ADODB.Connection") 'make connection
object
'send connection string to database, via oject
conn.ConnectionString = aConnectionString
'open the connection
conn.Open()
SQL = ("SELECT aValue FROM aTable WHERE theCondition='" + aCondition
+ "'")
R = conn.execute(SQL, RecsAffected, adCmdText)
For Each F In R.Fields
Response.Write("") 'do nothing
Next
While Not R.EOF
For Each F In R.Fields
aValue = F.Value
Next
R.MoveNext()
End While
conn.Close()
End Sub
--
Martin Eyles ma**********@NOSPAM.bytronic.com 6 1471
Marin,
Glad to see you are turning on Option Explicit and Option Strict.
You can early bind like this:
dim connection as System.Data.SqlClient.SqlConnection
connection = new System.Data.SqlClient.SqlConnection
of course, if you Import System.Data.SqlClient at the top of your page, this
looks a lot nicer:
dim connection as SqlConnection
connection = new SqlConnection()
or
dim connection as SqlConnection = new SqlConnection()
also look at exception handling (try/catch) and if you are serious about
properly learning VB.Net, check out http://www.amazon.com/exec/obidos/AS...185744-5788008
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Martin Eyles" <ma**********@NOSPAM.bytronic.com> wrote in message
news:10*************@corp.supernews.com... I have just turned on option strict in ASP/VB.net. I started by happily going through and setting up all of the Dim statements with As clauses,
and making my cast explicit. However, I have now got stuck on "late binding". After reading that early binding is faster, I think that it would be best
to make everything early binding, but I can't work out how. have but a
sample of my database code below. Can anyone tell me how to fix it?
Thanks, Martin
Public Sub aSub() 'Allocate Variables Dim adCmdText, aConnectionString, SQL As String Dim R, F, RecsAffected As Object Dim conn As Object
'set connection string for login to database aConnectionString = "Provider=SQLOLEDB;Data Source=server;" _ & "Database=aDataBase;UID=aUserID;PWD=aPassword" conn = Server.CreateObject("ADODB.Connection") 'make connection object 'send connection string to database, via oject conn.ConnectionString = aConnectionString 'open the connection conn.Open()
SQL = ("SELECT aValue FROM aTable WHERE theCondition='" +
aCondition + "'") R = conn.execute(SQL, RecsAffected, adCmdText) For Each F In R.Fields Response.Write("") 'do nothing Next While Not R.EOF For Each F In R.Fields aValue = F.Value Next R.MoveNext() End While
conn.Close() End Sub
-- Martin Eyles ma**********@NOSPAM.bytronic.com
I have done that now, and the connection object complained that it didn't
have the execute method. I found there is a SqlCommand class too from an
example in the help, and so have added the following code:-
anSQLCommand = New System.Data.SqlClient.SqlCommand
anSQLCommand.Connection() = conn
anSQLCommand.CommandText = SQL
My problem is that there are four different execute... methods in the
SqlCommand object:- NonQuery, Reader, Scalar and XmlReader. Could you
explain which ones I need, and how to use them? Also, are these ADODB like
my old code, or are they the new ADO.net classes? Does this make any
difference?
Thanks again,
Martin
--
Martin Eyles ma**********@NOSPAM.bytronic.com
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:Oi**************@TK2MSFTNGP10.phx.gbl... Marin, Glad to see you are turning on Option Explicit and Option Strict.
You can early bind like this:
dim connection as System.Data.SqlClient.SqlConnection
connection = new System.Data.SqlClient.SqlConnection
of course, if you Import System.Data.SqlClient at the top of your page,
this looks a lot nicer:
dim connection as SqlConnection connection = new SqlConnection()
or
dim connection as SqlConnection = new SqlConnection()
also look at exception handling (try/catch) and if you are serious about properly learning VB.Net, check out http://www.amazon.com/exec/obidos/AS...185744-5788008
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Martin Eyles" <ma**********@NOSPAM.bytronic.com> wrote in message news:10*************@corp.supernews.com... I have just turned on option strict in ASP/VB.net. I started by happily going through and setting up all of the Dim statements with As clauses, and making my cast explicit. However, I have now got stuck on "late
binding". After reading that early binding is faster, I think that it would be
best to make everything early binding, but I can't work out how. have but a sample of my database code below. Can anyone tell me how to fix it?
Thanks, Martin
Public Sub aSub() 'Allocate Variables Dim adCmdText, aConnectionString, SQL As String Dim R, F, RecsAffected As Object Dim conn As Object
'set connection string for login to database aConnectionString = "Provider=SQLOLEDB;Data Source=server;" _ & "Database=aDataBase;UID=aUserID;PWD=aPassword" conn = Server.CreateObject("ADODB.Connection") 'make connection object 'send connection string to database, via oject conn.ConnectionString = aConnectionString 'open the connection conn.Open()
SQL = ("SELECT aValue FROM aTable WHERE theCondition='" + aCondition + "'") R = conn.execute(SQL, RecsAffected, adCmdText) For Each F In R.Fields Response.Write("") 'do nothing Next While Not R.EOF For Each F In R.Fields aValue = F.Value Next R.MoveNext() End While
conn.Close() End Sub
-- Martin Eyles ma**********@NOSPAM.bytronic.com
Sorry, you are right, I changed you over from ADODB to ADO.Net...it does
make a difference. I obviously recommend that you move to ADO.Net, but now
might not be the correct time for you. If you are just doing this for
learning, strongly consider going with ADO.Net, if you have a deadline for a
project and ADODB is working, why not wait 'til downtime before rocking the
boat too much.
To use ADODB in a strongly-typed manner, you'll need to add a reference to
Microsoft ActiveX Data Object Library 2.7. You do this in VS.Net by right
clicking on "referneces", selecting "Add Reference", selecting the "COM" tab
and then picking that class.
Once added, you can do thigs like:
Dim connection As ADODB.Connection = New ADODB.Connection
connection.ConnectionString = ""
or
Dim rs as ADODB.Recordset = .....
and pretty much use it all like you are used to...
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Martin Eyles" <ma**********@NOSPAM.bytronic.com> wrote in message
news:10*************@corp.supernews.com... I have done that now, and the connection object complained that it didn't have the execute method. I found there is a SqlCommand class too from an example in the help, and so have added the following code:-
anSQLCommand = New System.Data.SqlClient.SqlCommand anSQLCommand.Connection() = conn anSQLCommand.CommandText = SQL
My problem is that there are four different execute... methods in the SqlCommand object:- NonQuery, Reader, Scalar and XmlReader. Could you explain which ones I need, and how to use them? Also, are these ADODB like my old code, or are they the new ADO.net classes? Does this make any difference?
Thanks again, Martin
-- Martin Eyles ma**********@NOSPAM.bytronic.com
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:Oi**************@TK2MSFTNGP10.phx.gbl... Marin, Glad to see you are turning on Option Explicit and Option Strict.
You can early bind like this:
dim connection as System.Data.SqlClient.SqlConnection
connection = new System.Data.SqlClient.SqlConnection
of course, if you Import System.Data.SqlClient at the top of your page, this looks a lot nicer:
dim connection as SqlConnection connection = new SqlConnection()
or
dim connection as SqlConnection = new SqlConnection()
also look at exception handling (try/catch) and if you are serious about properly learning VB.Net, check out http://www.amazon.com/exec/obidos/AS...185744-5788008
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Martin Eyles" <ma**********@NOSPAM.bytronic.com> wrote in message news:10*************@corp.supernews.com... I have just turned on option strict in ASP/VB.net. I started by
happily going through and setting up all of the Dim statements with As
clauses, and making my cast explicit. However, I have now got stuck on "late binding". After reading that early binding is faster, I think that it would be best to make everything early binding, but I can't work out how. have but a sample of my database code below. Can anyone tell me how to fix it?
Thanks, Martin
Public Sub aSub() 'Allocate Variables Dim adCmdText, aConnectionString, SQL As String Dim R, F, RecsAffected As Object Dim conn As Object
'set connection string for login to database aConnectionString = "Provider=SQLOLEDB;Data Source=server;" _ & "Database=aDataBase;UID=aUserID;PWD=aPassword" conn = Server.CreateObject("ADODB.Connection") 'make
connection object 'send connection string to database, via oject conn.ConnectionString = aConnectionString 'open the connection conn.Open()
SQL = ("SELECT aValue FROM aTable WHERE theCondition='" + aCondition + "'") R = conn.execute(SQL, RecsAffected, adCmdText) For Each F In R.Fields Response.Write("") 'do nothing Next While Not R.EOF For Each F In R.Fields aValue = F.Value Next R.MoveNext() End While
conn.Close() End Sub
-- Martin Eyles ma**********@NOSPAM.bytronic.com
I can afford a bit of time to get it going in ADO.net. Have figured out how
to get one value with scalar now, I think. The only thing now is working
with more data.
I am used to:- "Martin Eyles" <ma**********@NOSPAM.bytronic.com> wrote in message news:10*************@corp.supernews.com... > R = conn.execute(SQL, RecsAffected, adCmdText) > For Each F In R.Fields > Response.Write("") 'do nothing > Next > While Not R.EOF > For Each F In R.Fields > aValue = F.Value > Next > R.MoveNext() > End While
I think the first line should become R=command.executeReader, but what class
of object is R, and what changes do I have to make to the rest?
Thanks,
ME
--
Martin Eyles ma**********@NOSPAM.bytronic.com
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:e$**************@TK2MSFTNGP14.phx.gbl... Sorry, you are right, I changed you over from ADODB to ADO.Net...it does make a difference. I obviously recommend that you move to ADO.Net, but now might not be the correct time for you. If you are just doing this for learning, strongly consider going with ADO.Net, if you have a deadline for
a project and ADODB is working, why not wait 'til downtime before rocking
the boat too much.
To use ADODB in a strongly-typed manner, you'll need to add a reference to Microsoft ActiveX Data Object Library 2.7. You do this in VS.Net by right clicking on "referneces", selecting "Add Reference", selecting the "COM"
tab and then picking that class.
Once added, you can do thigs like: Dim connection As ADODB.Connection = New ADODB.Connection connection.ConnectionString = ""
or
Dim rs as ADODB.Recordset = .....
and pretty much use it all like you are used to...
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Martin Eyles" <ma**********@NOSPAM.bytronic.com> wrote in message news:10*************@corp.supernews.com... I have done that now, and the connection object complained that it
didn't have the execute method. I found there is a SqlCommand class too from an example in the help, and so have added the following code:-
anSQLCommand = New System.Data.SqlClient.SqlCommand anSQLCommand.Connection() = conn anSQLCommand.CommandText = SQL
My problem is that there are four different execute... methods in the SqlCommand object:- NonQuery, Reader, Scalar and XmlReader. Could you explain which ones I need, and how to use them? Also, are these ADODB
like my old code, or are they the new ADO.net classes? Does this make any difference?
Thanks again, Martin
-- Martin Eyles ma**********@NOSPAM.bytronic.com
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:Oi**************@TK2MSFTNGP10.phx.gbl... Marin, Glad to see you are turning on Option Explicit and Option Strict.
You can early bind like this:
dim connection as System.Data.SqlClient.SqlConnection
connection = new System.Data.SqlClient.SqlConnection
of course, if you Import System.Data.SqlClient at the top of your
page, this looks a lot nicer:
dim connection as SqlConnection connection = new SqlConnection()
or
dim connection as SqlConnection = new SqlConnection()
also look at exception handling (try/catch) and if you are serious
about properly learning VB.Net, check out http://www.amazon.com/exec/obidos/AS...185744-5788008
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
SqlDataReader dr = command.executeReader()
while dr.Read()
dim someField as string = cstr(dr("someColumn"))
end while
you might wanna check out an introduction on this sorta stuff such as
( http://www.sitepoint.com/article/introduction-ado-net/2) which I just got
from a google search...
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"Martin Eyles" <ma**********@NOSPAM.bytronic.com> wrote in message
news:10*************@corp.supernews.com... I can afford a bit of time to get it going in ADO.net. Have figured out
how to get one value with scalar now, I think. The only thing now is working with more data.
I am used to:-
> "Martin Eyles" <ma**********@NOSPAM.bytronic.com> wrote in message > news:10*************@corp.supernews.com... > > R = conn.execute(SQL, RecsAffected, adCmdText) > > For Each F In R.Fields > > Response.Write("") 'do nothing > > Next > > While Not R.EOF > > For Each F In R.Fields > > aValue = F.Value > > Next > > R.MoveNext() > > End While I think the first line should become R=command.executeReader, but what
class of object is R, and what changes do I have to make to the rest?
Thanks, ME
-- Martin Eyles ma**********@NOSPAM.bytronic.com
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:e$**************@TK2MSFTNGP14.phx.gbl... Sorry, you are right, I changed you over from ADODB to ADO.Net...it does make a difference. I obviously recommend that you move to ADO.Net, but
now might not be the correct time for you. If you are just doing this for learning, strongly consider going with ADO.Net, if you have a deadline
for a project and ADODB is working, why not wait 'til downtime before rocking the boat too much.
To use ADODB in a strongly-typed manner, you'll need to add a reference
to Microsoft ActiveX Data Object Library 2.7. You do this in VS.Net by
right clicking on "referneces", selecting "Add Reference", selecting the "COM" tab and then picking that class.
Once added, you can do thigs like: Dim connection As ADODB.Connection = New ADODB.Connection connection.ConnectionString = ""
or
Dim rs as ADODB.Recordset = .....
and pretty much use it all like you are used to...
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Martin Eyles" <ma**********@NOSPAM.bytronic.com> wrote in message news:10*************@corp.supernews.com... I have done that now, and the connection object complained that it didn't have the execute method. I found there is a SqlCommand class too from
an example in the help, and so have added the following code:-
anSQLCommand = New System.Data.SqlClient.SqlCommand anSQLCommand.Connection() = conn anSQLCommand.CommandText = SQL
My problem is that there are four different execute... methods in the SqlCommand object:- NonQuery, Reader, Scalar and XmlReader. Could you explain which ones I need, and how to use them? Also, are these ADODB like my old code, or are they the new ADO.net classes? Does this make any difference?
Thanks again, Martin
-- Martin Eyles ma**********@NOSPAM.bytronic.com
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:Oi**************@TK2MSFTNGP10.phx.gbl... > Marin, > Glad to see you are turning on Option Explicit and Option Strict. > > You can early bind like this: > > dim connection as System.Data.SqlClient.SqlConnection > > connection = new System.Data.SqlClient.SqlConnection > > of course, if you Import System.Data.SqlClient at the top of your page, this > looks a lot nicer: > > dim connection as SqlConnection > connection = new SqlConnection() > > or > > dim connection as SqlConnection = new SqlConnection() > > > also look at exception handling (try/catch) and if you are serious about > properly learning VB.Net, check out >
http://www.amazon.com/exec/obidos/AS...185744-5788008 > > > Karl > > -- > MY ASP.Net tutorials > http://www.openmymind.net/
Thankyou,
I think there is plenty of information to read on this. I had
googled a bit, but it helps to know what you are googling for, so thanks for
the link too.
ME
--
Martin Eyles ma**********@NOSPAM.bytronic.com
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:Oi**************@TK2MSFTNGP09.phx.gbl... SqlDataReader dr = command.executeReader() while dr.Read() dim someField as string = cstr(dr("someColumn")) end while
you might wanna check out an introduction on this sorta stuff such as (http://www.sitepoint.com/article/introduction-ado-net/2) which I just got from a google search...
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Martin Eyles" <ma**********@NOSPAM.bytronic.com> wrote in message news:10*************@corp.supernews.com... I can afford a bit of time to get it going in ADO.net. Have figured out how to get one value with scalar now, I think. The only thing now is working with more data.
I am used to:-
> > "Martin Eyles" <ma**********@NOSPAM.bytronic.com> wrote in message > > news:10*************@corp.supernews.com... > > > R = conn.execute(SQL, RecsAffected, adCmdText) > > > For Each F In R.Fields > > > Response.Write("") 'do nothing > > > Next > > > While Not R.EOF > > > For Each F In R.Fields > > > aValue = F.Value > > > Next > > > R.MoveNext() > > > End While
I think the first line should become R=command.executeReader, but what class of object is R, and what changes do I have to make to the rest?
Thanks, ME
-- Martin Eyles ma**********@NOSPAM.bytronic.com
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:e$**************@TK2MSFTNGP14.phx.gbl... Sorry, you are right, I changed you over from ADODB to ADO.Net...it
does make a difference. I obviously recommend that you move to ADO.Net, but now might not be the correct time for you. If you are just doing this for learning, strongly consider going with ADO.Net, if you have a deadline for a project and ADODB is working, why not wait 'til downtime before
rocking the boat too much.
To use ADODB in a strongly-typed manner, you'll need to add a
reference to Microsoft ActiveX Data Object Library 2.7. You do this in VS.Net by right clicking on "referneces", selecting "Add Reference", selecting the
"COM" tab and then picking that class.
Once added, you can do thigs like: Dim connection As ADODB.Connection = New ADODB.Connection connection.ConnectionString = ""
or
Dim rs as ADODB.Recordset = .....
and pretty much use it all like you are used to...
Karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"Martin Eyles" <ma**********@NOSPAM.bytronic.com> wrote in message news:10*************@corp.supernews.com... > I have done that now, and the connection object complained that it didn't > have the execute method. I found there is a SqlCommand class too
from an > example in the help, and so have added the following code:- > > anSQLCommand = New System.Data.SqlClient.SqlCommand > anSQLCommand.Connection() = conn > anSQLCommand.CommandText = SQL > > My problem is that there are four different execute... methods in
the > SqlCommand object:- NonQuery, Reader, Scalar and XmlReader. Could
you > explain which ones I need, and how to use them? Also, are these
ADODB like > my old code, or are they the new ADO.net classes? Does this make any > difference? > > Thanks again, > Martin > > -- > Martin Eyles > ma**********@NOSPAM.bytronic.com > > "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> > wrote in message news:Oi**************@TK2MSFTNGP10.phx.gbl... > > Marin, > > Glad to see you are turning on Option Explicit and Option Strict. > > > > You can early bind like this: > > > > dim connection as System.Data.SqlClient.SqlConnection > > > > connection = new System.Data.SqlClient.SqlConnection > > > > of course, if you Import System.Data.SqlClient at the top of your page, > this > > looks a lot nicer: > > > > dim connection as SqlConnection > > connection = new SqlConnection() > > > > or > > > > dim connection as SqlConnection = new SqlConnection() > > > > > > also look at exception handling (try/catch) and if you are serious about > > properly learning VB.Net, check out > > > http://www.amazon.com/exec/obidos/AS...185744-5788008 > > > > > > Karl > > > > -- > > MY ASP.Net tutorials > > http://www.openmymind.net/
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Clarence Gardner |
last post by:
I've got a problem that I don't see how to program around. A socket server
that was running fine, today started getting an exception from the bind()
call (errno 22, Invalid argument) and yet the...
|
by: Scott Robinson |
last post by:
I have been having trouble with the garbage collector and sockets.
Unfortunately, google keeps telling me that the problem is the garbage
collector ignoring dead (closed?) sockets instead of...
|
by: Achille Carette |
last post by:
Hello all,
I noticed a difference in the explain plans between JDBC using bind
variables (PreparedStatement) and SQLPlus for the same query. The query made
through JDBC using bind variables...
|
by: P G |
last post by:
I hope this is on topic here. I have a problem compiling a simple
example of the use of boost::bind. Please take a look at the program
below.
...
|
by: Arturo Cuebas |
last post by:
The program below contains a compile error. Following the program you
will find the typical fix then my idea for a library that facilitates
a more elegant fix.
#include <boost\bind.hpp>
using...
|
by: Heidi Hundåla |
last post by:
Hi !
I have a Wep App in C#.
Page_Unload fires after Page_Load, and
it seems totally unreasonable when you want to use this event when you
_leave_ the page.
In my project we wanted to use...
|
by: teclioness |
last post by:
Hi,
I am using gridview for the user to update rows. In a row, there sre
two columns, which need to be updated. When the gridview is to be
shown, the row should show the values from database....
|
by: Tigera |
last post by:
Greetings,
I am trying to learn to use the Boost library, and I've run into a
frustrating problem with the line marked here:
#include <boost/function.hpp>
#include <boost/functional.hpp>...
|
by: ADezii |
last post by:
The process of verifying that an Object exists and that a specified Property or Method is valid is called Binding. There are two times when this verification process can take place: during compile...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |