Insert into a table when clicking a button

M

Markus

Hallo i hope some one can help me i would like to update a db when clicking
on a button if some one can look over my code that would be a greate help.

function Update() {

Dim rs, strPfadDB, sSQL

strPfadDB = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("\fpdb\request_table.mdb") & _
";Mode=ReadWrite;Persist Security Info=False"

sSQL "insert into Audit (Requesd_ID, CDS_ID) values ('2000', 'mm')"
set rs = Server.CreateObject("ADODB.Recordset")
rs.Execute sSQL, strPfadDB, 1, 2
rs.Close
set rs = nothing
}
 
J

Jon Spivey

If you want to perform some action you'd use a sub rather than a function -
a function has to return a value. It's easiest to insert against a
connection.

sub Update()
set oConn = createobject("adodb.connection")
oConn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath("/fpdb/request_table.mdb")
oConn.execute "insert into Audit (Requesd_ID, CDS_ID) values ('2000', 'mm')"
oConn.close
set oConn = nothing
end sub

If Requesd_ID is a numeric field in your database don't enclose 2000 in
quotes - only strings need quotes.

Cheers,
Jon
 
M

Markus

Sorry for the stupid question i never used a sub before in a asp site can you
tell me how to use it and how to call the sub
 
S

Stefan B Rusynko

You Call the SUB the same way you are calling the FUNCTION
See http://www.w3schools.com/asp/asp_procedures.asp
But since you are not using any parameters with each, and your values are hard coded in it
- you probably don't need to be using either a SUB or a FUNCTION






Sorry for the stupid question i never used a sub before in a asp site can you
tell me how to use it and how to call the sub
 
S

Stefan B Rusynko

PS
Naming routines (or any variables) in your code using reserved names is not allowed,
- and will generate errors
"Update" is a reserved name
- so rename your routine to something else - say: UpdateDB()




You Call the SUB the same way you are calling the FUNCTION
See http://www.w3schools.com/asp/asp_procedures.asp
But since you are not using any parameters with each, and your values are hard coded in it
- you probably don't need to be using either a SUB or a FUNCTION






Sorry for the stupid question i never used a sub before in a asp site can you
tell me how to use it and how to call the sub
 
J

Jon Spivey

Naming routines (or any variables) in your code using reserved names is
not allowed,
- and will generate errors
"Update" is a reserved name
- so rename your routine to something else - say: UpdateDB()

update is a reserved word in sql not in asp/VB Script, eg
<%
call update()
sub update()
response.write "the time is now " & now()
end sub
%>

no errors. But something like
<%
call option()
sub option()
response.write "the time is now " & now()
end sub
%>

Would give an error as option is a reserved word in VB Script.

Cheers,
Jon
 
J

Jon Spivey

Hi,
You'd use a sub like this
<%
Sub MySub(i)
response.write i + 1
end sub

call MySub(22)
%>

Compared to a function which would be like this
<%
function MyFunction(i)
MyFunction = i + 1
end function

response.write MyFunction(22)
%>

Both would of course give the same output - just different ways of doing it.

Cheers,
Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top