Reply
edit a database
Old 09-25-2007, 06:07 PM edit a database
Skilled Talker

Posts: 77
Code:
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("datab/db1.mdb")
Conn.Open

Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "SELECT * FROM affil", Conn, 1,3

straffillink = request.form("affillink")
straffilimage = request.form("affilimage")

Rs.addnew
Rs("affillink") = straffillink
Rs("affilimage") = straffilimage
Rs.update

set Rs = nothing
set Conn = nothing
%>
I tried this, but it give an error, and says the database or object it read only, and points at 'Rs.addnew'.

how can i fix this?
Skeddles is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 09-25-2007, 06:21 PM Re: edit a database
tripy's Avatar
Fetchez la vache!

Posts: 1,850
Name: Thierry
Location: In the void
well, at first sight, did you checked that the mdb file was not read-only for the server process ?

Or maybe the DB is locked. I don't know if access files implements locks though...
__________________
Listen to the ducky: "This is awesome!!!"

tripy is online now
Reply With Quote
View Public Profile
 
Old 09-25-2007, 08:04 PM Re: edit a database
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,945
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
You'd be better off with an insert query.

http://www.w3schools.com/sql/sql_insert.asp

You don't need a recordset object to use it. Just create your SQL query and use Conn.Execute (SQL query).
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 09-25-2007, 09:13 PM Re: edit a database
Skilled Talker

Posts: 77
Quote:
Originally Posted by ADAM Web Design View Post
You'd be better off with an insert query.

http://www.w3schools.com/sql/sql_insert.asp

You don't need a recordset object to use it. Just create your SQL query and use Conn.Execute (SQL query).
Sorry, im kinda new to this.

Code:
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("datab/db1.mdb")
Conn.Open

Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "SELECT * FROM affil", Conn, 1,3

straffillink = request.form("affillink")
straffilimage = request.form("affilimage")

INSERT INTO affil (link, image)
VALUES (straffillink, straffilimage)

set Rs = nothing
set Conn = nothing
%>
Now it tells me 'Expected end of statement' and points to 'affil' after INSERT INTO.
Skeddles is offline
Reply With Quote
View Public Profile
 
Old 09-25-2007, 09:14 PM Re: edit a database
Skilled Talker

Posts: 97
Name: Ganesh
Skeddles,

There could be couple of issues

1. Like tripy said

2. Make sure the IUSR_Machiname user has proper rights (Computer Management) to work with the .mdb file. This is internet guest user which is used by the IIS server to execute CGI.
__________________
Gather. Search. Compare. Save on Hotel and Flight Prices @ www.vtrip.info
sri_gan is offline
Reply With Quote
View Public Profile
 
Old 09-25-2007, 09:17 PM Re: edit a database
Skilled Talker

Posts: 97
Name: Ganesh
Quote:
Originally Posted by Skeddles View Post
Sorry, im kinda new to this.

Code:
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("datab/db1.mdb")
Conn.Open
 
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "SELECT * FROM affil", Conn, 1,3
 
straffillink = request.form("affillink")
straffilimage = request.form("affilimage")
 
INSERT INTO affil (link, image)
VALUES (straffillink, straffilimage)
 
set Rs = nothing
set Conn = nothing
%>
Now it tells me 'Expected end of statement' and points to 'affil' after INSERT INTO.

Skeddles,

Here is the fixed code.



Code:
<%
 
dim sql

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("datab/db1.mdb")
Conn.Open

Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "SELECT * FROM affil", Conn, 1,3

straffillink = request.form("affillink")
straffilimage = request.form("affilimage")

sql="INSERT INTO affil (link, image) VALUES ('" & straffillink & "','" & straffilimage & "')"
 
Conn.execute(sql)


set Rs = nothing
set Conn = nothing
%>
__________________
Gather. Search. Compare. Save on Hotel and Flight Prices @ www.vtrip.info
sri_gan is offline
Reply With Quote
View Public Profile
 
Old 09-26-2007, 05:20 PM Re: edit a database
Skilled Talker

Posts: 77
Quote:
Originally Posted by sri_gan View Post
Skeddles,

Here is the fixed code.



Code:
<%
 
dim sql

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("datab/db1.mdb")
Conn.Open

Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "SELECT * FROM affil", Conn, 1,3

straffillink = request.form("affillink")
straffilimage = request.form("affilimage")

sql="INSERT INTO affil (link, image) VALUES ('" & straffillink & "','" & straffilimage & "')"
 
Conn.execute(sql)


set Rs = nothing
set Conn = nothing
%>
Syntax error in INSERT INTO statement.
/addaffil.asp, line 18
Skeddles is offline
Reply With Quote
View Public Profile
 
Old 09-26-2007, 07:04 PM Re: edit a database
Learning Newbie's Avatar
Moderator

Latest Blog Post:
What Does This Look Like?
Posts: 4,712
Name: John Alexander
Replace

Conn.execute(sql)

with

If Request.IP = Your_IP_Address Then Response.Write("<br />" + sql + "<br />")
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is online now
Reply With Quote
View Public Profile
 
Old 09-27-2007, 10:16 AM Re: edit a database
Skilled Talker

Posts: 97
Name: Ganesh
Code:
 
<%
 
dim sql

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.ConnectionString = "Data Source=" & Server.MapPath ("datab/db1.mdb")
Conn.Open

Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open "SELECT * FROM affil", Conn, 1,3

straffillink = request.form("affillink")
straffilimage = request.form("affilimage")

if straffillink <>"" and straffilimage <>"" then
sql="INSERT INTO affil (link, image) VALUES ('" & straffillink & "','" & straffilimage & "')"
 
response.write (sql)
'Conn.execute(sql)
else
 
response.write ("affillink and affilimage are empty")

end if


set Rs = nothing
set Conn = nothing
%>
__________________
Gather. Search. Compare. Save on Hotel and Flight Prices @ www.vtrip.info
sri_gan is offline
Reply With Quote
View Public Profile
 
Old 09-27-2007, 02:15 PM Re: edit a database
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,945
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Does either your link or your image have an apostrophe in it?

If so, you'll have to do something like:

sql="INSERT INTO affil (link, image) VALUES ('" & Replace (straffillink, "'", "''") & "','" & Replace (straffilimage, "'", "''") & "')"

Your query looks fine other than that.
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 09-28-2007, 12:52 PM Re: edit a database
Skilled Talker

Posts: 97
Name: Ganesh
Yeah like ADAM mentioned, single quote could be a reason.

The next code I provided will show the sql statement, play with it and let me know what do you get.
__________________
Gather. Search. Compare. Save on Hotel and Flight Prices @ www.vtrip.info
sri_gan is offline
Reply With Quote
View Public Profile
 
Old 09-30-2007, 10:29 AM Re: edit a database
Skilled Talker

Posts: 77
'c:\windows\system32\inetsrv\datab\db1.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.
Skeddles is offline
Reply With Quote
View Public Profile
 
Old 09-30-2007, 10:51 AM Re: edit a database
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,945
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
That means your database has to be in the c:\windows\system32\inetsrv\datab folder and be named db1.mdb . At least one of those two things isn't true.
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 10-01-2007, 06:51 PM Re: edit a database
Skilled Talker

Posts: 77
Quote:
Originally Posted by ADAM Web Design View Post
That means your database has to be in the c:\windows\system32\inetsrv\datab folder and be named db1.mdb . At least one of those two things isn't true.
c:\windows\system32\inetsrv\datab\db1.mdb

well that doesnt really seem like a web adress. im not ure if thats the address of my server or not(i am using 1and1.com)

I really need to fix this though, i cant do much with my website untill its done.
Skeddles is offline
Reply With Quote
View Public Profile
 
Old 10-01-2007, 10:00 PM Re: edit a database
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,945
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
It's not a web address, and it's not supposed to be. It's supposed to be the path to your database.

Try using Server.MapPath ("datab/db1.mdb") instead.
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 10-07-2007, 05:39 AM Re: edit a database
Novice Talker

Posts: 7
First,check your datebase's attribute.You database may be read - only.

If your database is not a read-only one,then you must close your database first! It is important!!!! If you open a database first in a way,and then you open it again,you will not be able to open it.So before you open it again,please close it at first.
xuzheng is offline
Reply With Quote
View Public Profile
 
Old 10-10-2007, 05:04 PM Re: edit a database
Skilled Talker

Posts: 77
finally got it

Last edited by Skeddles : 10-10-2007 at 08:12 PM.
Skeddles is offline
Reply With Quote
View Public Profile
 
Old 10-12-2007, 12:35 PM Re: edit a database
Learning Newbie's Avatar
Moderator

Latest Blog Post:
What Does This Look Like?
Posts: 4,712
Name: John Alexander
What was the answer, Skeddles? Just in case someone else has the same problem n all.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to edit a database