ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old August 20th, 2003, 06:22 AM
decker27 decker27 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 decker27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Insert Probelms

I am producing a page that tracks jobs, for reference the method of payment is inserted into my database. Using javascript the user (using radio buttons) can show/hide table rows that contain Form fields for Amex(3), Cheque(1) or Cash(1). My Probelm is that the page will only insert if all 3 Amex fields have entered values, but because of the jave script you cant see the 3 Amex fields if you choose Cheque or Cash - I am using access and have set the field to Required No and Allow Zero Length Yes.
The insert code is:
<%

if(Request("JobID") <> "") then Command1__varJobID = Request("JobID")

if(Request("Quantity") <> "") then Command1__varQuantity = Request("Quantity")

if(Request("Size") <> "") then Command1__varSize = Request("Size")

if(Request("SizeCustom") <> "") then Command1__varSizeCustom = Request("SizeCustom")

if(Request("Stock") <> "") then Command1__varStock = Request("Stock")

if(Request("Range") <> "") then Command1__varRange = Request("Range")

if(Request("Finishing") <> "") then Command1__varFinishing = Request("Finishing")

if(Request("Security") <> "") then Command1__varSecurity = Request("Security")

if(Request("Cost") <> "") then Command1__varCost = Request("Cost")

if(Request("DeliveryName") <> "") then Command1__varDeliveryName = Request("DeliveryName")

if(Request("DeliveryTel") <> "") then Command1__varDeliveryTel = Request("DeliveryTel")

if(Request("DeliveryAddress") <> "") then Command1__varDeliveryAddress = Request("DeliveryAddress")

if(Request("PaymentType") <> "") then Command1__varPaymentType = Request("PaymentType")

if(Request("Payer1") <> "") and (Request("Payer2") = "") and (Request("Payer3") = "") then Command1__varPayer = Request("Payer1")

if(Request("Payer1") = "") and (Request("Payer2") <> "") and (Request("Payer3") = "") then Command1__varPayer = Request("Payer2")

if(Request("Payer1") = "") and (Request("Payer2") = "") and (Request("Payer3") <> "") then Command1__varPayer = Request("Payer3")

if(Request("AmexNumber") <> "") then Command1__varAmexNumber = Request("AmexNumber")

if(Request("AmexMonth") <> "") then Command1__varAmexMonth = Request("AmexMonth")

if(Request("AmexYear") <> "") then Command1__varAmexYear = Request("AmexYear")

if(Request("ContractNumber") <> "") then Command1__varContractNumber = Request("ContractNumber")

if(Request("SapBann") <> "") then Command1__varSapBann = Request("SapBann")

if(Request("AmountReceived") <> "") then Command1__varAmountReceived = Request("AmountReceived")

%>
<%

set Command1 = Server.CreateObject("ADODB.Command")
Command1.ActiveConnection = MM_Publishing_STRING
Command1.CommandText = "INSERT INTO PrtCopy (JobID, Quantity, Size, SizeCustom, Stock, Range, Finishing, Security, Cost, DeliveryName, DeliveryTel, DeliveryAddress, PaymentType, Payer, AmexNumber, ExpiryMonth, ExpiryYear, ContractNumber, SapBann, AmountReceived) VALUES (" + Replace(Command1__varJobID, "'", "''") + ", '" + Replace(Command1__varQuantity, "'", "''") + "', '" + Replace(Command1__varSize, "'", "''") + "', '" + Replace(Command1__varSizeCustom, "'", "''") + "','" + Replace(Command1__varStock, "'", "''") + "','" + Replace(Command1__varRange, "'", "''") + "','" + Replace(Command1__varFinishing, "'", "''") + "','" + Replace(Command1__varSecurity, "'", "''") + "'," + Replace(Command1__varCost, "'", "''") + ",'" + Replace(Command1__varDeliveryName, "'", "''") + "','" + Replace(Command1__varDeliveryTel, "'", "''") + "','" + Replace(Command1__varDeliveryAddress, "'", "''") + "','" + Replace(Command1__varPaymentType, "'", "''") + "','" + Replace(Command1__varPayer, "'", "''") + "'," + Replace(Command1__varAmexNumber, "'", "''") + "," + Replace(Command1__varAmexMonth, "'", "''") + "," + Replace(Command1__varAmexYear, "'", "''") + ",'" + Replace(Command1__varContractNumber, "'", "''") + "','" + Replace(Command1__varSapBann, "'", "''") + "'," + Replace(Command1__varAmountReceived, "'", "''") + ") "
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()

%>


Does anybody know how I can insert if some of my fields are empty?.

Thanks in advance

D

Reply With Quote
  #2  
Old August 20th, 2003, 06:34 AM
tomsn tomsn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: Dresden, Germany
Posts: 44 tomsn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 13 m 9 sec
Reputation Power: 5
Send a message via ICQ to tomsn
hi,

first little advices. try to use select-cases or try to interleave the if-statements, you'll need not so much code and you have a better overview.

in addition the escape-character between variables and strings is not "+", but "&" (if you use vbscript)

my suggestion is that the sql-string is wrong. for getting the error try this:
Code:
on error resume next
dim strSQL
set Command1 = Server.CreateObject("ADODB.Command") 
....
strSQL = "INSERT blabla...."
Command1.CommandText = strSQL
Command1.Execute() 

if err.number <> 0 then

Response.Write strSQL & "<br>"
Response.Write err.description

end if
on error goto 0


or print the variable strSQL before executing the SQL-String.
-->Copy-Paste into Access and see what happens....

tom

Last edited by tomsn : August 20th, 2003 at 06:36 AM.

Reply With Quote
  #3  
Old August 20th, 2003, 08:31 AM
decker27 decker27 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 decker27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi Tom,
Thanks for responding. I have changed the code to:
<% If Request("Submit") <> "" Then %>
<%
Dim strJobCode, strQuantity, strSize, strSizeCustom, strStock, strRange, strFinishing, strSecurity, strCost, strDeliveryName, strDeliveryTel, strDeliveryAddress, strPaymentType
Dim objConn, strInsert

'gather form field values
strJobCode = Replace(request("JobCode"), "'", "''")
strQuantity = Replace(request("Quantity"), "'", "''")
strSize = Replace(request("Size"), "'", "''")
strSizeCustom = Replace(request("SizeCustom"), "'", "''")
strStock = Replace(request("Stock"), "'", "''")
strRange = Replace(request("Range"), "'", "''")
strFinishing = Replace(request("Finishing"), "'", "''")
strSecurity = Replace(request("Security"), "'", "''")
strCost = Replace(request("Cost"), "'", "''")
strDeliveryName = Replace(request("DeliveryName"), "'", "''")
strDeliveryTel = Replace(request("DeliveryTel"), "'", "''")
strDeliveryAddress = Replace(request("DeliveryAddress"), "'", "''")
strPaymentType = Replace(request("PaymentType"), "'", "''")


'create and open a connection
Set objConn = Server.CreateObject("ADODB.Connection")

objConn.Open MM_Publishing_STRING

'define the append query
strInsert = "INSERT INTO PrtCopy (JobID, Quantity, Size, SizeCustom, Stock, Range, Finishing, Security, Cost, DeliveryName, DeliveryTel, DeliveryAddress, PaymentType) VALUES ('"&strJobCode&"', '"&strQuantity&"', '"&strSize&"', '"&strSizeCustom&"', '"&strStock&"', '"&strRange&"', '"&strFinishing&"', '"&strSecurity&"', '"&strCost&"', '"&strDeliveryName&"', '"&strDeliveryTel&"', '"&strDeliveryAddress&"', '"&strPaymentType&"')"

objConn.Execute()
%>
<% End IF %>

But now I get the following error:
Error Type:
Microsoft VBScript runtime (0x800A01C2)
Wrong number of arguments or invalid property assignment: 'Execute'

Any Ideas Why?

Reply With Quote
  #4  
Old August 20th, 2003, 08:55 AM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 4 m 10 sec
Reputation Power: 75
You need to tell it what to execute: objConn.execute(strInsert)

Reply With Quote
  #5  
Old August 20th, 2003, 09:03 AM
decker27 decker27 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 5 decker27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cheers Karsh, Just figured that out myself although I was worried it would write to the Database as soon as the page is loaded. However obvously the If statement stops it.

Thanks again

Reply With Quote
  #6  
Old August 20th, 2003, 09:37 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
OK the first thing I have to ask is:
Why are you doing this?

if(Request("JobID") <> "") then Command1__varJobID = Request("JobID")

Why don't you simply do:
Command1__varJobID = Request("JobID")

Why not? I mean after all, your variable Command1__varJobID is *STILL* inside your INSERT query so it doesn't make any sense?

and another thing...what if the user decides to enter a *SPACE* using the space bar then when you do:
if(Request("JobID") <> "") then Command1__varJobID = Request("JobID")

You'll insert a *space* into your variable Command1__varJobID You don't even Trim() it ?

I *STRONGLY* suggest to change the way you're doing things...look at this and it turns out to be the EXACT same thing but cleaner code and more efficient.

Here...I've attached the .asp page...have a look!

Hope this helps!
Sincerely

Vlince
Attached Files
File Type: asp tmp.asp (6.7 KB, 229 views)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Insert Probelms


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway