Yes, I want to be able to save the records to a table called labels. The labels table will be used in another part of the program. There a few other functions, but lets get throught this part first.
-Gabe
-Gabe
dim labelsRS
set labelsRS = server.createobject("adodb.recordset")
labelsRS.open "SELECT * FROM labels", cnnSearch, 2,3
'opens a recordset that allows you to add, delete, or update records
do until rstSearch.eof
labelsRS.addNew()
labelsRS("bin") = rstSearch("bin")
labelsRS("nomen") = rstSearch("nomen")
labelsRS("nsn") = rstSearch("nsn")
labelsRS("sell") = rstSearch("sell")
labelsRS("oha") = rstSearch("oha")
labelsRS.Update()
rstSearch.moveNext
loop
<%
for each x in request.form
response.write x & ": " & request.form(x) & "<br>" & vbNewLine
next
dim recordsToQuery
Dim strDBPath ' path to our Access database (*.mdb) file
strDBPath = Server.MapPath("database.mdb")
for each x in request.form
if request(x) = "ON" then
recordsToQuery = recordsToQuery & x & ","
end if
next
'recordsToQuery should now be a list of numbers the user selected
'i.e. "1234,2345,3456,"
'remove trailing comma
recordsToQuery = left(recordsToQuery, len(recordsToQuery)-1)
query = "SELECT * FROM [labels] WHERE id IN (" & recordsToQuery & ")"
'then check to make sure this works. Open the db connection just like
'previous and list the records just to make sure you pulled up the right
Set cnnSearch = Server.CreateObject("ADODB.Connection")
cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
Set rstSearch = cnnSearch.Execute(query)
dim labelsRS
set labelsRS = server.createobject("adodb.recordset")
labelsRS.open "SELECT * FROM labels", cnnSearch, 2,3
'opens a recordset that allows you to add, delete, or update records
do until rstSearch.eof
labelsRS.Delete()
labelsRS.Update()
rstSearch.moveNext
loop
%>
on error resume next
Set cnnSearch = Server.CreateObject("ADODB.Connection")
cnnSearch.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
set labelsRS = server.createobject("adodb.recordset")
for each x in request.form
if request(x) = "ON" then
query = "SELECT * FROM labels WHERE id = " & x
labelsRS.open query,cnnSearch,2,3
labelsRS.delete
if err.number=0 then %>
<h2>The entry <%=x%> has been deleted</h2>
<%
else %>
<h2>There was an error deleting record <%=x%>:</h2>
Error #<%=err.number%>: <%=err.description%>
<%
end if
labelsRS.close
end if
next
<%
' Declare our variables... always good practice!
Dim cnnSimple ' ADO connection
Dim rstSimple ' ADO recordset
Dim strDBPath ' path to our Access database (*.mdb) file
' MapPath of virtual database file path to a physical path.
' If you want you could hard code a physical path here.
strDBPath = Server.MapPath("database.mdb")
' Create an ADO Connection to connect to the scratch database.
' We're using OLE DB but you could just as easily use ODBC or a DSN.
Set cnnSimple = Server.CreateObject("ADODB.Connection")
' This line is for the Access sample database:
cnnSimple.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
' We're actually using SQL Server so we use this line instead:
'cnnSimple.Open "Provider=SQLOLEDB;Data Source=10.2.2.133;" _
' & "Initial Catalog=samples;User Id=samples;Password=password;" _
' & "Connect Timeout=15;Network Library=dbmssocn;"
' Execute a query using the connection object. It automatically
' creates and returns a recordset which we store in our variable.
Set rstSimple = cnnSimple.Execute("SELECT * FROM labels")
' Display a table of the data in the recordset. We loop through the
' recordset displaying the fields from the table and using MoveNext
' to increment to the next record. We stop when we reach EOF.
%> </h2>
<center>
<form action="print.asp" method="post">
<table border="1">
<tr>
<th bgcolor="#3D80C2">id</th>
<th bgcolor="#3D80C2">Location</th>
<th bgcolor="#3D80C2">Nomenclature</th>
<th bgcolor="#3D80C2">NSN</th>
<th bgcolor="#3D80C2">U/P</th>
<th bgcolor="#3D80C2"># Labels</th>
</tr>
<%
Do While Not rstSimple.EOF
%>
<tr>
<td bgcolor="#FFCC00"><%= rstSimple.Fields("id").Value %> </td>
<td bgcolor="#FFCC00"><%= rstSimple.Fields("bin").Value %> </td>
<td bgcolor="#FFCC00"><%= rstSimple.Fields("nomen").Value %> </td>
<td bgcolor="#FFCC00"><%= rstSimple.Fields("nsn").Value %> </td>
<td bgcolor="#FFCC00"><%= rstSimple.Fields("sell").Value %> </td>
<td bgcolor="#FFCC00">
<p align="center"><input type="text" name="Labelcnt" value="1" size="2"></td>
</tr>
<%
rstSimple.MoveNext
Loop
%>
</table>
<input type="button" value="Button" name="B1">
</form>
<%
' Close our recordset and connection and dispose of the objects
rstSimple.Close
Set rstSimple = Nothing
cnnSimple.Close
Set cnnSimple = Nothing
%>
Comment