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

rs.next and insert

Status
Not open for further replies.

davmold

IS-IT--Management
Jul 16, 2007
29
US
Hello All,

I am working on a project.
I have an asp script that returns all the records for a work id in my db. The data that I get looks somewhat like this

Work Order

1234
12345
12346
12347


What I am trying to accomplish is to convert each order into a button so the user can click on the order and it inserts that number into my db

I know how to do an insert and how to show the records but how could I do both?

here is the way I show the records

Code:
<%@LANGUAGE=VBSCRIPT%>
<%
Option Explicit 
Dim strConnection, conn, rs, strSQL 

strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("dp_asptut.mdb") & ";User Id=admin;Password=;"

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open strConnection

Set rs = Server.CreateObject("ADODB.recordset")
strSQL = "SELECT * FROM mo"
rs.open strSQL, conn, 3,3

rs.MoveFirst
WHILE NOT rs.EOF
     Response.Write(rs("monumber") & "<br/>") 
rs.MoveNext
WEND

rs.Close
Set rs = Nothing

conn.Close
Set conn = Nothing 
%>

any help or pointers are always appreciated

Thanks
 
just to give you an idea...try something like this:

Code:
WHILE NOT rs.EOF
     Response.Write("<a href= ""#"" onclick = 'ViewDetail("&rs("monumber")&")'>Click Here</a>") 
rs.MoveNext
WEND

and then you can write the function ViewDetail for the onclick event...code above is not tested...so check for corrections...

-DNG

 
So they will have the option to only enter one at a time? I would do a checkbox so they can enter multiple records(if needed) First you need to set a form

Code:
<form method="POST" action="Update.asp">
<% WHILE NOT rs.EOF
     Response.Write"<input type='checkbox' name='WorkOrders' value='"& rs("monumber") &"'>"& rs("monumber") &"<br>"
    rs.MoveNext
WEND%>
  <p><input type="submit" value="Submit" name="B1"></p>
</form>


Then you need your insert
 
thank you dotnetgnat that gives me an start but still don't understand it very well.


thecandyman,
I am trying to do a touch screen. Users in here are not very technology savy so we are trying to implement the easiest was possible
 
what did you not understand...did you get any error...do let us know...people here are very active and will definitely help you out...

-DNG
 
I got the lines to show but now I have to change the "click here" with the work order number

I tried
Code:
Response.Write("<br>""<a href= ""#"" onclick = 'ViewDetail("&rs("monumber")&")'><% resopnse.write(rs("monumber"))</a>""</br>")

but this did not work
 
try this:

Code:
Response.Write("<br>""<a href= ""#"" onclick = 'ViewDetail("&rs("monumber")&")'>"&rs("monumber")&"</a>""</br>")

just mess with quotes and use the right number of quotes...

-DNG
 
You are already server side when you start this line. The quotes are kinda hairy, but it should look like this:

Code:
Response.Write("<a href= ""#"" onclick = ""ViewDetail(" & rs("monumber") & ")"">[!]" & rs("monumber") & "[/!]</a><br />")

[monkey][snake] <.
 
Ok, it works,
now to insert the work order number into an access db, I know how to write a regular insert
Code:
<%
'variables
dim Conn, Connstring, Sql
dim strfirstname, strlastname, strage, strgender

Set Conn = Server.CreateObject("ADODB.Connection")

' assign variables to items in the forms collection.
strfirstname = request.form("monumber")

          
'database connection
Conn.provider = provider
Conn.ConnectionString = dbasepath
Conn.Open

'Sql statement to insert the data
Sql="INSERT INTO mytable (monumber) VALUES ('" _
	& monumber & "')"

' execute it
Conn.Execute(Sql)

Response.Write "Data successfully inserted!"
%>

but how can integrate both??
 
could I do something like

dim sql, intable

Response.Write("<a href= ""#"" onclick = intable ""ViewDetail(" & rs("monumber") & ")"">" & rs("monumber") & "</a><br />")


Sql="INSERT INTO mytable (monumber) VALUES ('" _
& monumber & "')"

' execute it
Conn.Execute(Sql)
 
you need to say something like...

<script language="javascript">
function ViewDetail(mnum){
location.ref="}
</script>

then on the mypage.asp

do the insert code which you have shown in your previous post...

but change this line:

strfirstname = request.form("monumber")

to

mynumber = request.querystring("mnum")

please check for errors...havent test the code...just trying to give you idea...

-DNG
 
so the enter page should be something like

Code:
<%
Option Explicit 
Dim strConnection, conn, rs, strSQL 

strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath("dp_asptut.mdb") & ";User Id=admin;Password=;"

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open strConnection

Set rs = Server.CreateObject("ADODB.recordset")
strSQL = "SELECT * FROM mo"
rs.open strSQL, conn, 3,3

rs.MoveFirst
WHILE NOT rs.EOF
     
Response.Write("<a href= ""#"" onclick = ""ViewDetail(" & rs("monumber") & ")"">" & rs("monumber") & "</a></p><br />")

rs.MoveNext
WEND

rs.Close
Set rs = Nothing

conn.Close
Set conn = Nothing 
%> 
<html>
<head>

<script language="javascript">
function ViewDetail(mnum){
location.ref="[URL unfurl="true"]http://mynetwork/mypage.asp?"+mnum;[/URL]
}
</script>

</head>

a

and the mypage.asp
wold look like this


Code:
Set Conn = Server.CreateObject("ADODB.Connection")

' assign variables to items in the forms collection.
mynumber = request.querystring("mnum")

          
'database connection
Conn.provider = provider
Conn.ConnectionString = dbasepath
Conn.Open

'Sql statement to insert the data
Sql="INSERT INTO mytable (monumber) VALUES ('" _
	& mynumber & "')"

' execute it
Conn.Execute(Sql)

Response.Write "Data successfully inserted!"
%>

This does not give me any errors but when I click on the work order, nothing happens
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top