Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Other Programming > VBScript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 18th, 2005, 11:52 AM
Authorized User
 
Join Date: Jul 2003
Location: Memphis, TN, USA.
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default Script To Write to Dbase HELP!!!

Hi,
I have a form that sends the info in the
completed boxes to a server. The server then
sends me a response message that is parsed into
table form per a subroutine. THAT ALL WORKS FINE.
Problem is with the sub I've tried to write to
add the same response msg info into a database.
Here's the code for both:
------------
'This function writes out the parsed return data in a table format
Sub WriteReturnData(strMsg)
    DIM arrNames(9), arrValues(9)
    arrNames(0)="Merchant Id"
    arrNames(1)="Transaction Type"
    arrNames(2)="Total Amount"
    arrNames(3)="First Name"
    arrNames(4)="Last Name"
    arrNames(5)="Response Type"
    arrNames(6)="Response Code"
    arrNames(7)="Response Description"
    arrNames(8)="Authorization Code"
    arrNames(9)="Trace Number"

    arrValues(0)=ParseString(strMsg,"pg_merchant_id=")
    arrValues(1)=ParseString(strMsg,"pg_transaction_ty pe=")
    arrValues(2)=ParseString(strMsg,"pg_total_amount=" )
    arrValues(3)=ParseString(strMsg,"ecom_billto_posta l_name_first=")
    arrValues(4)=ParseString(strMsg,"ecom_billto_posta l_name_last=")
    arrValues(5)=ParseString(strMsg,"pg_response_type= ")
    arrValues(6)=ParseString(strMsg,"pg_response_code= ")
    arrValues(7)=ParseString(strMsg,"pg_response_descr iption=")
    arrValues(8)=ParseString(strMsg,"pg_authorization_ code=")
    arrValues(9)=ParseString(strMsg,"pg_trace_number=" )

    Response.Write "<center><P><B>Response For Your Check Transaction</B></P>"
    Response.Write "<Table border=0>"
    FOR i=0 TO UBOUND(arrValues)
        IF arrValues(i) > "" THEN
            Response.Write "<tr>"
            Response.Write "<td align=right>" & arrNames(i) & ":&nbsp;</td>"
            Response.Write "<td>" & arrValues(i) & "</td>"
            Response.Write "</tr>"
        END IF
    NEXT
    Response.Write "</Table></center>"

End Sub

' This function 'should' add the same response data above to the datatable "Transactions_TransactionLogVBSForm"
Sub AddReturnData(strMsg)
DIM adoConnection, strSQL
DIM arrValues(8)
SET adoConnection = Server.CreateObject("ADODB.Connection")
adoConnection.ConnectionString = "Driver={SQL Server}; Server=local\thePhile; Database=thePhile; UID=sa; PWD=xxx"
strSQL = "INSERT INTO Transactions_TransactionLogJSForm(TransactionType, TotalAmount, Name, CompanyName, ResponseType, ResponseCode, ResponseDescr, AuthCode, TraceNo)"
strSQL = strSQL & "VALUES(arrValues(0)=ParseString(strMsg, "pg_transaction_type="),"
strSQL = strSQL & "arrValues(1)=ParseString(strMsg,"pg_total_amount= "),arrValues(2)=ParseString(strMsg,"ecom_billto_po stal_name_first="),arrValues(3)=ParseString(strMsg ,"ecom_billto_postal_name_last="),"
strSQL = strSQL & "arrValues(4)=ParseString(strMsg,"pg_response_type ="),arrValues(5)=ParseString(strMsg,"pg_response_c ode="), arrValues(6)=ParseString(strMsg,"pg_response_descr iption="),"
strSQL = strSQL & "arrValues(7)=ParseString(strMsg,"pg_authorization _code="), arrValues(8)=ParseString(strMsg,"pg_trace_number=" ))"
adoConnection.Execute(strSQL)

adoConnection.Close
adoConnection = Nothing
End Sub
------------------
...I know the sub "AddReturnData" is wrong but I don't kow how because I don't normally write VBScript. I am up to the "VALUES..."
line of the strSQL and I'm geting the following error msg:
---------------
Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/ThePhileVB/_check_purchase.asp, line 118, column 60
strSQL = strSQL & "VALUES(arrValues(0)=ParseString(strMsg, "pg_transaction_type="),"
-----------------------------------------------------------^
------------
...it seems like I might just have a syntax error, but don't know for sure.
Any suggestions how to fix this really appreciated.
Thx
Reid C.

Reid C.
__________________
Reid C.
Reply With Quote
  #2 (permalink)  
Old January 19th, 2005, 05:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ok, on this line
Code:
strSQL = strSQL & "VALUES(arrValues(0)=ParseString(strMsg, "pg_transaction_type="),"
what u have at the mo will just write the literal string "arrValues(0)=ParseString..." into the SQL. but what u really want to do is write the value of whatever is returned by ParseString(strMsg, "pg_transaction_type=") into the SQL, here's how you do it:
Code:
strSQL = strSQL & "VALUES('" & ParseString(strMsg, "pg_transaction_type=") & "',"
then u repeat that for each field. A few things to watch out for:
- if the field type is numeric u don't put '' around the value
- don't add the , after the last field (obvious I know, but easy to miss)
- if any of the values have ' inside them u need to Replace that with ''

If u still have probs add "Response.Write strSQL" just before the execute, then u can see exactly what you're sending to the db.

Personally, I would put all this in a stored procedure and run it using a Command object and named parameters - much easier to see what's going on then.

hth
Phil
Reply With Quote
  #3 (permalink)  
Old January 19th, 2005, 01:50 PM
Authorized User
 
Join Date: Jul 2003
Location: Memphis, TN, USA.
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thx much,
I made the changes you suggested and it executes and gives me the
response page as usual but it does not add the info to the dbase.
I'm still learning a little bit here so let me tell you that I got
this VBscript file from someone and I put it into an existing solution
in Visual Studio that has an open connection to the database. I assume
from that, that it should write to the d-base if the code is correct.
Is there anything I should check?--Here is my code after the changes
yu suggested:
----------------
Sub AddReturnData(strMsg)
DIM adoConnection, strSQL
DIM arrValues(8)
SET adoConnection = Server.CreateObject("ADODB.Connection")
adoConnection.ConnectionString = "Driver={SQL Server}; Server=local\thePhile; Database=thePhile; UID=sa; PWD=xxx"
strSQL = "INSERT INTO Transactions_TransactionLogJSForm(TransactionType, TotalAmount, Name, CompanyName, ResponseType, ResponseCode, ResponseDescr, AuthCode, TraceNo)"
strSQL = strSQL & "VALUES(""" & ParseString(strMsg, "pg_transaction_type=") & ""","""
strSQL = strSQL & ParseString(strMsg, "pg_total_amount=") & ""","""
strSQL = strSQL & ParseString(strMsg, "pg_name_first=") & ""","""
strSQL = strSQL & ParseString(strMsg, "pg_name_last=") & ""","""
strSQL = strSQL & ParseString(strMsg, "pg_response_type=") & ""","""
strSQL = strSQL & ParseString(strMsg, "pg_response_code=") & ""","""
strSQL = strSQL & ParseString(strMsg, "pg_response_description=") & ""","""
strSQL = strSQL & ParseString(strMsg, "pg_authorization_code=") & ""","""
strSQL = strSQL & ParseString(strMsg, "pg_trace_number=") & ")"
Response.Write strSQL
adoConnection.Execute(strSQL)

adoConnection.Close
adoConnection = Nothing
End Sub
-----------------
Thanks again for your help.
Reid C.

Reid C.
Reply With Quote
  #4 (permalink)  
Old January 20th, 2005, 04:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

u need to use single quote ' not double quote " to surround non-numeric fields values
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write a script to download file Ivanchan Other Programming Languages 0 January 24th, 2008 04:56 AM
connection to dbase jardbf Classic ASP Basics 0 May 23rd, 2006 04:10 AM
Multiple Connections to dBase derekinit Classic ASP Databases 0 June 3rd, 2005 09:35 PM
Write a script to select particular field from DB choudhmh Pro VB.NET 2002/2003 1 January 28th, 2005 07:37 AM
SQL Server: Copy Table From dbase to other dbase orez SQL Server 2000 3 July 7th, 2004 03:51 AM



All times are GMT -4. The time now is 03:34 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.