Click to See Complete Forum and Search --> : [RESOLVED] how to insert data using ahref in sql server..


omarr226
04-14-2006, 05:33 PM
ok now..my topic doesnt seems to be understandable so i'll explain my situation in a more detailed way>>>

i want to insert data which is coming from sqlserver through ahref..
now on my 1st page, lets say, Select.asp i have listed a combo box and wen i select any of da listed values and hit da search button, many records according to da search criteria user has defined, are displayed in da Searched.asp page. Now da question is i dont know how many records will be shown, dey can be 0 or as many as possible. Now wat i want is to include a link "Apply" wid each displayed record. This link is redirected to another page, lets say, Apply.asp and it only stores da id of da displayed record (from Searched.asp) which ofcourse will be coming from database and can be understood as its primary key, in a new table in Apply.asp. Everything is nicely coded, not even a single error, but the problem is dat id of da particular displayed record is not inserting into da database, instead only 0 is being inserted everytime i click any of da "Apply" link.
The data type i have used in da main table from which da records r being shown is bigint and also in da table in whch dat id is going to be inserted.

i have used da following code in Searched.asp


<%Response.Write "<a href=""http://localhost/son/apply.asp?ID=" & rs("jobid")& """>Apply</a>"%>

wid da loop and etc etc..!!

now da Apply.asp>>>

jobno=request.form("jobid")
sql="insert into jobcv(jobid)values('"&jobno&"')"
rsinsert.open sql,con,1,2
Response.write("applied")

'rsinsert.close
1 more thing... wenever i close da rsinsert recordset, error is shown dat

Error Type:
ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.



now plz help me wats wrong wid da code..!!!
why everytime 0 is inserted and y not da id of da selected record..!!!?????????????????? :eek: :eek: :eek:

chrismartz
04-15-2006, 08:55 AM
When you insert the information into the table, is the id column set to be an identity and automatically create an id? If not, you should do that.

Ubik
04-15-2006, 08:58 AM
What happens when you do this:

<%Response.Write "<a href=""http://localhost/son/apply.asp?ID=" & rs("jobid")& """>Apply for Job Number: " & rs("jobid") & " </a>"%>

I would also advise not doing this, it makes things confusing later:
jobno=request.form("jobid")

Try this instead:
if isnumeric(request.form("jobid")) then
intJobId=request.form("jobid")
else
intJobId=0
response.write "JobID is not numeric"
end if

In your sql and db, you are using a numeric value as a string, which should be discouraged:
sql="insert into jobcv(jobid)values('"&jobno&"')"

You should change jobcv.jobid to an int type, and use:
sql="insert into jobcv(jobid)values("&jobno&")"

I hope that helps.

omarr226
04-15-2006, 02:31 PM
no its not working..!!!!
0 is being inserted in da jobid field of table jobcv....da datatype in da master table where da records are being displayed in searched.asp page is bigint and da datatype in jobcv is aslo bigint

here is da complete code of apply.asp


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<%
dim con,rsinsert,rs
dim sql,jobno,sql1,cvno
set con=server.CreateObject("ADODB.connection")
set rs=server.CreateObject("Adodb.recordset")
set rsinsert=server.CreateObject("Adodb.recordset")



con.ConnectionString="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=son;Data Source=(local)"
con.open()



sql1="select cvno from cv where userid=11"
rs.open sql1,con,1,2

cvno=rs("cvno")
if isnumeric(request.form("jobid")) then
jobno=request.form("jobid")
sql="insert into jobcv(cvno,jobid)values('"&cvno&"','"&jobno&"')"
rsinsert.open sql,con,3,4
Response.write("applied")
else
jobno=0
response.write ("JobID is not numeric")
end if




rs.close
'rsinsert.close
'set rsinsert= nothing
set rs = nothing

con.close

%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Apply</title>
</head>

<body>

</body>
</html>

i did not mention in my 1st post dat i also want to add cvno which is ofcourse coming from other table, but dat is fine and it is being added but da prb is only in da jobid field... y 0 is being added???

omarr226
04-15-2006, 02:44 PM
just want to add...>>>>>

i tried single quote wid da jobid field but its not working...dere is an error dat >>
Syntax error near ')'
something like dat...........

Ubik
04-16-2006, 11:30 AM
Because you are calling request.form("jobid") when I think you want request.querystring("jobid")