I am stuck for few days

I am stuck for few days

am 07.04.2006 22:36:40 von Vedran Grubac

Hi guys I need help. I have page vich is linked with database, and it needs
to have some sort of editing text. No addning, or deleting. I know how to
display text from database, but I am stuck on editng it. So question is how
to edit page with ID let's say 10 (getting "old" text in text area for
change and submitnig it to change). Every page in tbale has ID and text.

Re: I am stuck for few days

am 08.04.2006 10:04:10 von Mike Brind

Vedran Grubac wrote:
> Hi guys I need help. I have page vich is linked with database, and it needs
> to have some sort of editing text. No addning, or deleting. I know how to
> display text from database, but I am stuck on editng it. So question is how
> to edit page with ID let's say 10 (getting "old" text in text area for
> change and submitnig it to change). Every page in tbale has ID and text.

What have you tried in the last few days? Have you googled for "ASP
Database Update Tutorial"? Have you found some code and tried it?
Have you got some error message from trying it? If so, post the code
and the error message, telling us which line caused the error. Also
tell us which type and version of database you are using.

--
Mike Brind

Re: I am stuck for few days

am 08.04.2006 13:56:26 von vgrubac

Ok database is access 2003, mdb
code is
update_form.asp
<%
Dim adoCon
Dim rsText
Dim strSQL
Dim lngRecordNo

lngRecordNo = CLng(Request.QueryString("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("tim.mdb")
Set rsText = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT str.* FROM str WHERE ID=" & lngRecordNo
rsText.Open strSQL, adoCon
%>


Update Form




Name: ">


Comments: ">
">




<%
rsText.Close
Set rsText = Nothing
Set adoCon = Nothing
%>
That part of code is ok, and form retrives data from database....
next is
update_entry.asp:

<%
Dim adoCon
Dim rsUpdateEntry
Dim strSQL
Dim lngRecordNo

lngRecordNo = CLng(Request.Form("ID"))

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("tim.mdb")
Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT str.* FROM str WHERE ID=" & lngRecordNo

rsUpdateEntry.CursorType = 2
rsUpdateEntry.LockType = 3
rsUpdateEntry.Open strSQL, adoCon
rsUpdateEntry.Fields("Stranica") = Request.Form("name")
rsUpdateEntry.Fields("Text") = Request.Form("comments")
rsUpdateEntry.Update


rsUpdateEntry.Close
Set rsUpdateEntry = Nothing
Set adoCon = Nothing

Response.Redirect "update_select.asp"
%>

And error is somewher in this two lines of code:

rsUpdateEntry.Fields("Stranica") = Request.Form("name")
rsUpdateEntry.Fields("Text") = Request.Form("comments")


Database tbale str has columns ID, Stranica, Text
Any idea?

Re: I am stuck for few days

am 08.04.2006 20:59:32 von Mike Brind

Lots to go on here. See inline comments:

vgrubac@gmail.com wrote:
> Ok database is access 2003, mdb
> code is
> update_form.asp
> <%
> Dim adoCon
> Dim rsText
> Dim strSQL
> Dim lngRecordNo
>
> lngRecordNo = CLng(Request.QueryString("ID"))
>
> Set adoCon = Server.CreateObject("ADODB.Connection")
> adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
> Server.MapPath("tim.mdb")

You shouldn't be using the ODBC driver. It's been deprecated. You
should be using the native OLEDB driver instead. See
http://www.aspfaq.com/show.asp?id=2126.
Your path suggests you have the mdb file in the same directory as the
script. You should not do this. It should be kept somewhere outside
the root of the website. Otherwise anyone can browse to it and
download a copy.

> Set rsText = Server.CreateObject("ADODB.Recordset")
> strSQL = "SELECT str.* FROM str WHERE ID=" & lngRecordNo

You shouldn't SELECT * unless you really do want to use all the fields
in your database. I see you do actually use all the fields in this
case, but from a legibility and maintainability point of view, this is
still poor practice. And in any case, you shouldn't select the ID
number. You already have that in the Request.QueryString collection.
See here: http://www.adopenstatic.com/faq/selectstarisbad.asp

> rsText.Open strSQL, adoCon
> %>
>
>
> Update Form
>
>
>
>


> Name: ">
>

> Comments: ">

Are you really limiting the length of comments, or should you be using
a textarea here?

> ">
>
>

>
>
> <%
> rsText.Close
> Set rsText = Nothing
> Set adoCon = Nothing
> %>
> That part of code is ok, and form retrives data from database....
> next is
> update_entry.asp:
>
> <%
> Dim adoCon
> Dim rsUpdateEntry
> Dim strSQL
> Dim lngRecordNo
>
> lngRecordNo = CLng(Request.Form("ID"))

There is no field called ID in your form. You have called it ID_no.
Consequently, IngRecordNo will never have any value.

>
> Set adoCon = Server.CreateObject("ADODB.Connection")
> adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
> Server.MapPath("tim.mdb")

ODBC again. See above.

> Set rsUpdateEntry = Server.CreateObject("ADODB.Recordset")
> strSQL = "SELECT str.* FROM str WHERE ID=" & lngRecordNo

You should not be using a recordset to update fields in your database.

>
> rsUpdateEntry.CursorType = 2
> rsUpdateEntry.LockType = 3
> rsUpdateEntry.Open strSQL, adoCon
> rsUpdateEntry.Fields("Stranica") = Request.Form("name")
> rsUpdateEntry.Fields("Text") = Request.Form("comments")
> rsUpdateEntry.Update
>
>
> rsUpdateEntry.Close
> Set rsUpdateEntry = Nothing
> Set adoCon = Nothing
>
> Response.Redirect "update_select.asp"
> %>
>
> And error is somewher in this two lines of code:
>
> rsUpdateEntry.Fields("Stranica") = Request.Form("name")
> rsUpdateEntry.Fields("Text") = Request.Form("comments")

It may be the second line. The problem could be caused by your use of
"Text" as a field name. It's a reserved word in both Access and Jet.
See http://www.aspfaq.com/show.asp?id=2080, but it's more likely that
you have no data in your ID field, because you referenced a form field
that doesn't exist.

>
>
> Database tbale str has columns ID, Stranica, Text
> Any idea?

Yes. Use a saved parameter query to do the update. Go into Access and
in the Query pane, select Create Query in Design View. Close the Add
Table dialogue box that appears and switch to SQL view. Copy and paste
the following:

UPDATE str SET Stranica = [p1], [Text] = [p2] WHERE ID = [p3]

and save that as qUpdateComment. Run the query. You will be prompted
for values for p1,p2,p3. Put something sensible in to make sure it
works. p3 should obviously be an existing ID number.

[Text] has square brackets around it to get round the reserved word
problem.
Consider renaming it to Comments or something.

Now your update_form.asp code should look like this:

<%
dim p1,p2,p3,adocon

p1 = Request.Form("name")
p2 = Request.Form("comments")
p3 = Request.Form("ID_no")

set adocon = createobject("ADODB.Connection")
adocon.open ""
adocon.qUpdateComment p1,p2,p3
adocon.close: set adocon = nothing
response.write "Your comments have been updated"
%>

It's a lot easier, quicker, cleaner and safer to do it this way. You
don't have to worry about delimiting different datatypes, and because
you built and tested the query in Access, you know it will work.

--
Mike Brind

Re: I am stuck for few days

am 08.04.2006 23:41:21 von vgrubac

Ok I have one questin more (I konw, I konw I am bothering :(()

> Yes. Use a saved parameter query to do the update. Go into Access and
> in the Query pane, select Create Query in Design View. Close the Add
> Table dialogue box that appears and switch to SQL view. Copy and paste
> the following:
>
> UPDATE str SET Stranica = [p1], [Text] = [p2] WHERE ID = [p3]
>
> and save that as qUpdateComment. Run the query. You will be prompted
> for values for p1,p2,p3. Put something sensible in to make sure it
> works. p3 should obviously be an existing ID number.
>
> [Text] has square brackets around it to get round the reserved word
> problem.
> Consider renaming it to Comments or something.
>
I made that, and it works, and text is changed to samothing, query
works in
access

> Now your update_form.asp code should look like this:
>

Is that update_form, or entry_update wich is called after hitting
submit
button, if is first one, where it goes, becouse update_form retrives
data
from database in form?

> <%
> dim p1,p2,p3,adocon
>
> p1 = Request.Form("name")
> p2 = Request.Form("comments")
> p3 = Request.Form("ID_no")
>
> set adocon = createobject("ADODB.Connection")
> adocon.open ""
> adocon.qUpdateComment p1,p2,p3
> adocon.close: set adocon = nothing
> response.write "Your comments have been updated"
> %>
>
This should be connection or?

set adocon = createobject("ADODB.Connection")
adocon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("tim.mdb")

And after everything I get error
ADODB.Connection (0x800A0E7C)
Parameter object is improperly defined. Inconsistent or incomplete
information was provided.
for:
adocon.qUpdateComment p1,p2,p3

p.s. any good book convering this?

Re: I am stuck for few days

am 09.04.2006 00:14:20 von Mike Brind

vgrubac@gmail.com wrote:
> Ok I have one questin more (I konw, I konw I am bothering :(()
>
> > Yes. Use a saved parameter query to do the update. Go into Access and
> > in the Query pane, select Create Query in Design View. Close the Add
> > Table dialogue box that appears and switch to SQL view. Copy and paste
> > the following:
> >
> > UPDATE str SET Stranica = [p1], [Text] = [p2] WHERE ID = [p3]
> >
> > and save that as qUpdateComment. Run the query. You will be prompted
> > for values for p1,p2,p3. Put something sensible in to make sure it
> > works. p3 should obviously be an existing ID number.
> >
> > [Text] has square brackets around it to get round the reserved word
> > problem.
> > Consider renaming it to Comments or something.
> >
> I made that, and it works, and text is changed to samothing, query
> works in
> access
>
> > Now your update_form.asp code should look like this:
> >
>
> Is that update_form, or entry_update wich is called after hitting
> submit
> button, if is first one, where it goes, becouse update_form retrives
> data
> from database in form?
>
> > <%
> > dim p1,p2,p3,adocon
> >
> > p1 = Request.Form("name")
> > p2 = Request.Form("comments")
> > p3 = Request.Form("ID_no")
> >
> > set adocon = createobject("ADODB.Connection")
> > adocon.open ""
> > adocon.qUpdateComment p1,p2,p3
> > adocon.close: set adocon = nothing
> > response.write "Your comments have been updated"
> > %>
> >
> This should be connection or?
>
> set adocon = createobject("ADODB.Connection")
> adocon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
> Server.MapPath("tim.mdb")
>
> And after everything I get error
> ADODB.Connection (0x800A0E7C)
> Parameter object is improperly defined. Inconsistent or incomplete
> information was provided.
> for:
> adocon.qUpdateComment p1,p2,p3
>
> p.s. any good book convering this?

Sorry - that should have been entry_update.asp - or whatever page you
do your processing on. Peronally, I always post this sort of form page
back to itself and have both the form and the processing code on the
same page. Then I test to see if the form has been submitted:

If Request.Form("ID")<>"" then
'process the results
Else
'present the form
End If

The error you get is telling you that a value is missing - probably in
p3. Check the name of the hidden ID field in your form against the
processing code where p3 picks up its value. They should both be named
ID_no (or both be named ID - whichever you prefer). I got that error
the first time I ran your code - that's how I noticed that you had
named the form field one thing in the form, and another in the
processing code.

Get rid of the ODBC driver, please. Change your connection string to
this:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.Mappath("tim.mdb")

As far as books are concerned, I have Beginning ASP 3.0 (Wrox) and ASP
Developers Guide (McGraw Hill). Both are good for beginners. Neither
of them covers saved parameter queries, though. That's something I
picked up from regularly visiting this group.

--
Mike Brind

Re: I am stuck for few days

am 09.04.2006 13:19:13 von Vedran Grubac

"Mike Brind" wrote in message
news:1144534459.975205.152070@u72g2000cwu.googlegroups.com.. .
>

Thanks man, everythung works OK now, last problem I fgured out without your
post. Somethime all you need is a good night sleep. Simple as that.