Re: update table with the word Null
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Thu, 20 Sep 2007 12:41:31 -0400
Joe T wrote:
Here's the code:<snip>
Recordset1_cmd.ActiveConnection = MM_stellco_STRING
This is a horrible coding practice. You need to get away from using
Dreamweaver and learn to code without that crutch. Your current problem
illustrates why I say that (see below).
The reason this is horrible is, because it forces ADO to create a new
connection behind the scenes, it kills performance by disabling connection
pooling. Best practices include creating an explicit Connection object in
your page and using it for your recordset and Command objects that you
create later on in the page. Like this:
Dim cn
Set cn = CreateObject("adodb.connection")
cn.open MM_stellco_STRING
....
Set Recordset1_cmd.ActiveConnection = cn
<snip>
<%
UPDATE projects
SET floorplan = "Null"
WHERE floorplan = ""
%>
OK, here is the problem with using Dreamweaver to generate bad code: you
never learn how to write code, good or otherwise, yourself. Vbscript will
not run a sql statement in a database on its own. It needs some help from
ADO, specifically from an ADO Command object. Like this:
Dim sql
sql=UPDATE projects SET floorplan = 'Null' WHERE floorplan =''"
'for debugging:
Response.Write sql
'comment out the above line when finished debugging
dim cmd
set cmd=createobject("adodb.command")
With cmd
.CommandText=sql
.CommandType = 1 'adCmdText
Set .ActiveConnection=cn 'see above
.Execute ,,128 'adExecuteNoRecords
End With
cn.close: set cn=nothing
In this case, since there are no parameters, you don't need to explicitly
create the Command object, you can use the Connection's Execute method which
will cause a Command object to be created implicitly behind the scenes:
Dim sql
sql=UPDATE projects SET floorplan = 'Null' WHERE floorplan =''"
'for debugging:
Response.Write sql
'comment out the above line when finished debugging
cn.Execute sql,,129 'adCmdText + adExecuteNoRecords
Again, I suggest you take a look at the links I provided in my previous
message.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
.
- Follow-Ups:
- Re: update table with the word Null
- From: Joe T
- Re: update table with the word Null
- References:
- update table with the word Null
- From: Joe T
- Re: update table with the word Null
- From: Bob Barrows [MVP]
- Re: update table with the word Null
- From: Joe T
- Re: update table with the word Null
- From: Joe T
- Re: update table with the word Null
- From: Bob Barrows [MVP]
- Re: update table with the word Null
- From: Joe T
- Re: update table with the word Null
- From: Bob Barrows [MVP]
- Re: update table with the word Null
- From: Joe T
- update table with the word Null
- Prev by Date: Re: File Upload From Clients Computer
- Next by Date: Re: Replace file if smaller in size
- Previous by thread: Re: update table with the word Null
- Next by thread: Re: update table with the word Null
- Index(es):
Relevant Pages
|