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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to do a simple update...

Status
Not open for further replies.

booboo0912

Programmer
Jul 31, 2002
75
US
Hello! I'm trying to update a database using a form, and I've looked at many examples, but can't figure out why my code isn't working. I'm using ASP and JScript, but the examples I've seen are using VBScript, so I'm trying to translate into JScript. I've only gotten as far as filtering the records to the one that needs to be updated, and now I'm trying to set up the form to put the data in text boxes so the data can be updated.

Here's where I'm stuck:

<%
FindTime = Request.QueryString(&quot;FindTime&quot;);

conn = Server.CreateObject(&quot;ADODB.Connection&quot;);
conn.Open(Application(&quot;CONN_STR&quot;));

rs = Server.CreateObject(&quot;ADODB.Recordset&quot;);

sSQL = &quot;Select b.Time, a.Appt1, a.Appt2, a.Appt3, a.Appt4 From tblSubCholesterol a join tblCholesterol b on b.TimeID and b.Time = &quot; + &quot;'&quot; + Request.Form(&quot;FindTime&quot;) + &quot;'&quot;;

rs.Open(sSQL, conn);

strAppt1 = rs(&quot;Appt1&quot;);
strAppt2 = rs(&quot;Appt2&quot;);
strAppt3 = rs(&quot;Appt3&quot;);
strAppt4 = rs(&quot;Appt4&quot;);

%>

When I try to display a field using a simple alert box:

<script language=&quot;Javascript&quot;>
alert(<%=strAppt1%>);
</script>

I get an error message saying: &quot;Error Type: ADODB.Field
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires current record.&quot;

What am I doing wrong?? I appreciate any help!!
Thanks!
T
 
try this ...

sSQL = &quot;Select b.Time, a.Appt1, a.Appt2, a.Appt3, a.Appt4 From tblSubCholesterol a join tblCholesterol b on b.TimeID and b.Time = '&quot; + Request.Form(&quot;FindTime&quot;) + &quot;' &quot;;

Hope it help
 
what the message is telling you is that it can't find any records...response.write the sql statement to ensure that you are calling it correctly (all field names correct, syntax correct etc) if that is okay then

just response.write the recordset to see if there is data...

if there is why not just create an update form?

<form name=updateData method = post action = muUpdate.asp>
<table><tr><td>
name</td><td><input type = text name=username value =&quot;<%=rs.(&quot;username&quot;)%>&quot;>
</td></tr></table></form>
<input type=submit value=update>


hth
Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Thank you both for your help. I changed the last part of my select statement, but I'm getting a new error message. It claims there's incorrect syntax near '0830', which is the correct value of FindTime. When I hard code 0830 in the select statement, the value of the corresponding field is displayed. But for some reason, it won't let me pass a string variable or request.Form/QuerySring.

Any other ideas??? I feel like I'm sooooo close!
Thanks!
 
if the time is a date/time field, you don't need the quotes around the value... Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
The Time field is a varchar...what's really weird, is that when I use the string variable with no single quotes, just double quotes, it works. Check it out..seems pretty odd to me...

sSQL = &quot;Select b.Time, a.Appt1, a.Appt2, a.Appt3, a.Appt4 From tblSubCholesterol a join tblCholesterol b on b.TimeID and b.Time = &quot;+FindTime+&quot;&quot;;

Still not sure how or why that works, but it does! Kinda makes me nervous! :)
Thanks for your help!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top