Re: Update an SQL database



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"



.



Relevant Pages

  • Tell Betty its romantic emphasizing in a meaning.
    ... If the comfortable requests can compare probably, ... techniques. ... runs to greek David, who's allowing worth the dose's benefit. ... easy myth won't review before I echo it. ...
    (sci.crypt)
  • Re: Comparing Two Identical Tables - Loop Through fields in a Recordset
    ... two tables and writing to a recordset of the third table? ... Field7 = GG ... dim db as database, rs as recordset, cSQL as string ... 'COMPARE NUMERIC DATA - ABSOLUTE % CHANGE ...
    (comp.databases.ms-access)
  • Re: diff(ing) 2 directories ?
    ... compare directory trees recursively and report the differences. ... echo "softlink" ... # compare a file, directory, or softlink ... cat << EOU Usage: $0 dir1 dir2 Compare directory trees: files are binary compared directories are checked for identical content soft links are checked for identical targets ...
    (comp.lang.tcl)
  • Comparing file trees to check for compromised system.
    ... I ended up using Bit Twister's ideas to write a script to compare two ... for dir1 in $dirlist; do ... # echo "directory:" $dir1 ...
    (comp.os.linux.security)
  • Re: Handsets from Vodafone
    ... they're nothing to compare to the Nokia ones ... that seem to echo around the room, but I tend to use it on increasing ring ...
    (uk.telecom.mobile)