Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 21st, 2005, 03:56 PM
Registered User
 
Join Date: Feb 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL back to web form

Hi,

What would be the best way to get data back from a database, I want to be able to edit records. I used the following to add or "INSERT" the data:

Set conn = server.createobject("adodb.connection")
DSNtemp = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("/database/store01/login.mdb")
conn.Open DSNtemp

If Request.Form("T1") > "" Then
    uid = Request.Form("T1")
    pwd = Request.Form("T2")
    titl = Request.Form("T3")
    wor = Request.Form("T4")
    mob = Request.Form("T5")
    fax = Request.Form("T6")
    adm = Request.Form("C7")
Else
Conn.Execute(SQL)
Conn.Close
Response.Redirect "index.asp"
End If
SQL = "Insert INTO contacts (uid,pwd,titl,wor,mob,fax,adm) VALUES ('" & uid & "','" & pwd & "','" & titl & "','" & wor & "','" & mob & "','" & fax & "', " & adm & ")"
Conn.Execute(SQL)
Conn.Close
Response.Redirect "index.asp"

I am stumped as to how to get this data back to the form.

Can anybody help?

Thanks

 
Old February 21st, 2005, 05:25 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Use a "SELECT" query to retrieve your record, something like this
"SELECT field1,field2... FROM Contacts WHERE Criterida = <some criteria> and then populate your form fields.
for e.g. if you have text field name title

<input type="text" name="title" value="<%= Title %>" maxlength="35">




 
Old February 21st, 2005, 06:01 PM
Registered User
 
Join Date: Feb 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,

I've got this from the top of my page, I have another page selecting the record, then this page editing it. I am not getting anything with this is it correct?

Any ideas?

<%
which = Request.QueryString("which")
id = Request.QueryString("id")
SQL = "Select uid From " & which & " Where ID =" & id
%>

<html>
<head>
<title>Admin</title>
</head>
<body>
<table border="0" width="100%">
  <tr>
    <td width="33%" colspan="3" valign="bottom"><form method="POST" action="add.asp"><b>Add User</b></td>
  </tr>
  <tr>
    <td width="33%">Full Name<br>
      <input type="text" name="T1" size="30" value="<%= uid %>"></td>

 
Old February 21st, 2005, 06:15 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

I think u missed the <form> tag..

<form name=form1>
<table border="0" width="100%">
  <tr>
    <td width="33%" colspan="3" valign="bottom"><form method="POST" action="add.asp"><b>Add User</b></td>
  </tr>
  <tr>
    <td width="33%">Full Name<br>
      <input type="text" name="T1" size="30" value="<%= uid %>"></td>
.
.
.
.
</form>

Om Prakash
 
Old February 21st, 2005, 06:21 PM
Registered User
 
Join Date: Feb 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks,

I still have a problem with the value of T1 is this the correct way to add the value from the database?

<input type="text" name="T1" size="30" value="<%= uid %>"></td>

 
Old February 22nd, 2005, 01:11 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

<input type="text" name="T1" size="30" value="<%=rs("uid")%>">


Om Prakash
 
Old February 22nd, 2005, 02:23 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

first create recordset object, populate variables corresponding the form fields and then display those variables
<%
something like this...
'Recordset Object
Dim strSQL
strSQL = "Your SQL Query"
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strSQL, ConnObj,adOpenKeyset, adLockOptimistic

'Populate your variables
Dim uid
uid = rs("uid")

'Close your recordset
rs.Close
Set rs = Nothing
%>

display form field
<input type="text" name="T1" value="<%= uid%>">





Similar Threads
Thread Thread Starter Forum Replies Last Post
form back color; saidan C# 2005 12 October 29th, 2007 08:16 AM
Why does the form always post back? Conch General .NET 9 January 9th, 2007 04:12 PM
Giving focus back to form Tethys Access VBA 1 March 7th, 2006 03:24 AM
Save simple record via web form t sql database kbarsi VB Databases Basics 1 January 30th, 2005 11:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.