Re: Update an SQL database
- From: "Daniel Crichton" <msnews@xxxxxxxxxxxxxxxx>
- Date: Wed, 25 Jun 2008 14:13:31 +0100
Try using Echo for every row in the recordset, just before you do the
comparison, to print out what the value of that column is - could it be that
you're using a CHAR column rather than VARCHAR and so all the columns are
padded with spaces?
Dan
Meat wrote on Wed, 25 Jun 2008 06:08:04 -0700:
Hello Bob,
The vbscrit isn't run by an asp page, I run it manually on a server to
see if my connection and querie to the SQL database is working well.
That's why
I put those WScript.Echo. I watch it live and I click OK when needed.
The problem I got is with this line :
**********************************************************
If objRecordSet.Fields("Server") = strServerName Then
**********************************************************
It seems that this line isn't working, because I do not see the
WScript.Echo lines after, even if I know that this condition is true.
Do I need to convert both variables into text or any other kind of data
to be able to compare them?
Thank you.
"Bob Barrows [MVP]" wrote:
Meat wrote:
Hi,
I want to update a record into a SQL server 2000 database. When I
want to compare my variable with the record in the database, I can't
say why but it's not working, the script continues without doing
what
I want it to do :
Dim strServerName
strServerName = "servername"
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=SQLOLEDB;Data Source=SERVER;Initial
Catalog=DATABASE;User ID=USER;Password=PASSWORD"
objRecordSet.Open "SELECT * FROM TABLE", objConnection,
adOpenStatic, adLockOptimistic
Why retrieve all the fields?
http://www.aspfaq.com/show.asp?id=2096
objRecordSet.MoveFirst
Do Until objRecordSet.EOF = true
If objRecordSet.Fields("Server") = strServerName Then
****************************************************
WScript.Echo strServerName******************************************************
WScript.quit
Get rid of these lines. This code is running on the server where
there is likely nobody watching the monitor to click OK on the
dialog resulting from that Echo statement.
Actually, Wscript is not an object that is supported natively by the
ASP platform. Those two lines should have raised errors. Do you have
an on error resume next statement you haven't shown us?
Replace them with
Response.Write strServerName
Exit Loop
Else objRecordSet.MoveNext
End if
Loop
The problem is with the "If objRecordSet.Fields("Server") =
strServerName Then" line. Even if both variable are the same, it
doesn't do the WScript.Echo strServerName.
--
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"
.
- References:
- Re: Update an SQL database
- From: Bob Barrows [MVP]
- Re: Update an SQL database
- From: Meat
- Re: Update an SQL database
- Prev by Date: Re: Update an SQL database
- Next by Date: Re: Update an SQL database
- Previous by thread: Re: Update an SQL database
- Next by thread: Re: Update an SQL database
- Index(es):
Relevant Pages
|