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!

SQL problem

Status
Not open for further replies.

Glutus

Programmer
Jul 13, 2001
27
0
0
SE
I've got an Access database that I'm trying to update some data in. I'm re-using code that is working on other pages, so this is very peculiar. The page gets the data and the number of records sent from another page. The code looks like this:

nombre=Request.Form("nombre")
For a=1 to nombre
data1=Request.Form("data1")
data2=Request.Form("data2")
id=Request.Form("id")
SQL="Update MyTable Set Data1='"&data1
SQL=SQL+"',Data2='"&data2&"' Where [ID]="&id
MyConn.Execute(SQL)
Next

If I remove the "MyConn.Execute(SQL)" statement and add "Response.Write(SQL)", I can see that the SQL statements looks perfect, exactly like I want them. It's just that they don't work. Both "data1" and "data2" are in text format. I really need help, needed this done yesterday. Please, help me. Every advice, solution, or idea is of interest. Thx.
 
Try changing it to the following:

SQL = "Update MyTable Set Data1='" & data1
SQL = SQL & "',Data2='" & data2 & "' Where [ID]=" & id
Mise Le Meas,

Mighty :)
 
Sorry, my mistake. It should of course be:

SQL = SQL & "...

Thx anyway.
 
To explain myself. It's a typo. The problem persists.
 
What error messges are you getting???? Mise Le Meas,

Mighty :)
 
The page just won't load. I have no idea what's wrong.
 
You have a loop running from 1 to nombre. You don't access the loop variable "a" anywhere inside the loop. This means that you are trying to insert the same data over and over again. Surely this can't be right!! Mise Le Meas,

Mighty :)
 
What do you mean the page won't load?? Mise Le Meas,

Mighty :)
 
Maybe u should try to use
nombre=Int(Request.Form("nombre"))
cuz u need nombre as an Number not as an String...
________
George, M
 
Darn, I'm so sorry. It's another typo. It should read:

data1=Request.Form(a & "data1")
data2=Request.Form(a & "data2")
id=Request.Form(a & "id")
 
The loop runs perfectly when I type the individual SQLs. Like this:

Update MyTable Set Data1=1, Data2=2 Where ID=1
Update MyTable Set Data1=2, Data2=4 Where ID=2
Update MyTable Set Data1=3, Data2=6 Where ID=3
 
I forgot the apostrophes:

Update MyTable Set Data1='1', Data2='2' Where [ID]=1
Update MyTable Set Data1='2', Data2='4' Where [ID]=2
Update MyTable Set Data1='3', Data2='6' Where [ID]=3
 
To Mise Le Meas:

The page is blank when I try to run it. It just won't load.
 
could you cut and paste exactly what you have for code from your asp script? it could very well be just a minor typo or logic problem that will explain your problem.
 
Glutus,

Did you get a solution to your problem?
Can you post your complete code? If there is nothing loading, the chances are that there is an error in your code before it outputs to the screen. try to view the source of the blank page. You might see an error message at the end of the source. Mise Le Meas,

Mighty :)
 
Here's the complete code:

<%Language=VBScript%>
<%Response.Buffer=True%>

<html>
<body>

<%
aktion=Request(&quot;Action&quot;)

if aktion=&quot;Update&quot; then
Set MyConn=Server.CreateObject(&quot;ADODB.Connection&quot;)
MyConn.Open &quot;XXX&quot;

nombre=Request.Form(&quot;nombre&quot;)
For a=1 to nombre
instrument=Request.Form(a & &quot;instrument&quot;)
yield=Request.Form(a & &quot;yield&quot;)
id=Request.Form(a & &quot;ID&quot;)

SQL = &quot;Update MyTable Set&quot;
SQL = SQL & &quot; (Instrument = '&quot; & instrument & &quot;',&quot;
SQL = SQL & &quot; (Yield = '&quot; & yield & &quot;' Where [ID]=&quot; & id

'Response.Write SQL & &quot;<p>&quot;
MyConn.Execute(SQL)
Next
MyConn.Close
SWet MyConn=Nothing
End If

</body>
</html>
 
Here are some errors:

You have:

SQL = &quot;Update MyTable Set&quot;
SQL = SQL & &quot; (Instrument = '&quot; & instrument & &quot;',&quot;
SQL = SQL & &quot; (Yield = '&quot; & yield & &quot;' Where [ID]=&quot; & id

Should be:

SQL = &quot;Update MyTable Set &quot;
SQl = SQL & &quot;Instrument = '&quot; & instrument & &quot;', &quot;
SQL = SQL & &quot;Yield = '&quot; & yield & &quot;' &quot;
SQL = SQL & &quot;WHERE ID = &quot; & id

(You had two open parentheses but no closing ones.)

Also, you have:

SWet MyConn=Nothing

instead of:

Set MyConn = Nothing

Finally, you don't close off your asp section. You should have %> before the </body> tag.

Hope all that is of some help. Mise Le Meas,

Mighty :)
 
Thank you ever so much. You are gods. It was of course a silly typo, the closing of the parenteses. I finally found the error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top