Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Can I Modify SQL statement?

Status
Not open for further replies.

finnoscar

Technical User
Aug 17, 2002
55
0
0
GB
How could I modify the following code to allow a breeder to update the pups available field of their record in the breeders table?

<%@ LANGUAGE = JavaScript%>
<HTML>
<HEAD>
<meta name=&quot;Microsoft Theme&quot; content=&quot;indust 110, default&quot;>
</HEAD>
<BODY>
<%


// Connect to database
var adoConnection = Server.CreateObject(&quot;ADODB.Connection&quot;);
adoConnection.Open(&quot;DSN=CompDSN&quot;);
var adoRecordset;

// Create SQL to insert new Breeders into Breeders table
var mySQL = &quot;INSERT INTO Breeders &quot; +
&quot;(BreederName,BrPhoneNo ,BrAddress, PupsAvailable,BreedName)&quot;;
mySQL = mySQL + &quot; VALUES ('&quot; + Request.Form(&quot;txtBreederName&quot;) + &quot;','&quot;;
mySQL = mySQL + Request.Form(&quot;txtBrPhoneNo&quot;) + &quot;','&quot;;
mySQL = mySQL + Request.Form(&quot;txtBrAddress&quot;) + &quot;','&quot;;
mySQL = mySQL + Request.Form(&quot;txtPupsAvailable&quot;) + &quot;','&quot;;
mySQL = mySQL + Request.Form(&quot;txtBreedName&quot;) + &quot;','&quot;;

// Execute SQL to add new breeder
adoConnection.Execute(mySQL);


// Recordset not needed after this so close it and allow release of memory
adoRecordset.Close();
adoRecordset = null;



Response.Write(&quot;<H2><CENTER>Your Details have been added successfully&quot; +
&quot;</CENTER></H2>&quot;);
%>
</BODY>
</HTML>
 
Hi,
Try the following SQL:

&quot;Update Breeders Set PupsAvailable = &quot; & Val(Request.Form(&quot;txtPupsAvailable&quot;)) & &quot; where BreederName ='&quot; & Request.Form(&quot;breederName&quot;) & &quot;' and BreedName='&quot; & Request.Form(&quot;breedName&quot;) & &quot;'&quot;

Hope it helps. Let me know what happens.
With regards,
PGK
 
I get the following error message

Error Type:
Microsoft JScript compilation (0x800A03EC)
Expected ';'
/Update.asp, line 17, column 22
& &quot;WHERE BreederNo ='&quot;Request.Form(&quot;txtBreederNo&quot;) &&quot;'&quot;;
---------------------^
 
Hi,
Did you put in the & symbol in between the No=&quot; and Request.Form ?

Moreover, if BreederNo is a numeric value, then use the Val function as I have done in my query.

If BreederNo is numeric then:

& &quot;WHERE BreederNo=&quot; & Val(Request.Form(&quot;txtBreederNo&quot;))

Else if BreederNo is a string then:

& &quot;WHERE BreederNo='&quot; & Request.Form(&quot;txtBredderNo&quot;) & &quot;'&quot;

Note : If it is a string, the = symbol is followed by a single quote and then a double quote. If it is number, no single quotes before or after.

In case you still have problems, post your SQL string that is giving you the problem. I am sure someone will be help to help.

Hope it helps. Let me know what happens.

With regards,
PGK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top