 |
| 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
|
|
|
|

February 22nd, 2004, 01:27 PM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
adding records
Greetings Earthlings,
I am fairly new to ASP so please be gentle :)
I am trying to add records to my contact database. I have a basic idea as to how to do it, but I am now stuck. Below is a code that i have put together so far but it does not work. If Anyone's got some time and/or will to help out on this it would be greatly appreciated.
<%@ LANGUAGE="VBSCRIPT" %>
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open("contup")
sql = "INSERT INTO Contact (Contact_Name, Department, Phone1, Phone2, Cellular, Pager, Fax, Email, Details) VALUES ("
sql = sql & request.form("Contact_Name") & "','"
sql = sql & request.form("Department") & "','"
sql = sql & request.form("Phone1") & "','"
sql = sql & request.form("Phone2") & "','"
sql = sql & request.form("Cellular") & "','"
sql = sql & request.form("Pager") & "','"
sql = sql & request.form("Fax") & "','"
sql = sql & request.form("Email") & "','"
sql = sql & request.form("Details") & "')"
conn.execute(sql)
'response.write (sql)
%>
<html>
<head>
<title>Update Confirmation</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
</head>
<body>
<h2>UPDATE RESULTS</h2>
<b>
<p>You input the following data:</b></p>
<table border="1">
<tr>
<td>Contact Name </td>
<td><%=request.form("Contact_Name")%>
</td>
</tr>
<tr>
<td>Groups </td>
<td><%=request.form("Department")%>
</td>
</tr>
<tr>
<td>Phone 1 </td>
<td><%=request.form("Phone1")%>
</td>
</tr>
<tr>
<td>Phone 2 </td>
<td><%=request.form("Phone2")%>
</td>
</tr>
<tr>
<td>Cellular </td>
<td><%=request.form("Cellular")%>
</td>
</tr>
<tr>
<td>Pager </td>
<td><%=request.form("Pager")%>
</td>
</tr>
<tr>
<td>Fax </td>
<td><%=request.form("Fax")%>
</td>
</tr>
<tr>
<td>Email </td>
<td><%=request.form("Email")%>
</td>
</tr>
<tr>
<td>Details </td>
<td><%=request.form("Details")%>
</td>
</tr>
</table>
<p><br>
</p>
<h2>Add a Contact</h2>
<table>
<tr>
<td><form name="contactupdate" method="post" action="update.asp">
</form>
</td>
</tr>
<tr>
<td align="right"><b>Name</b></td>
<td><input type="text" name="Contact_Name" size="40"> </td>
</tr>
<tr>
<td align="right"><b>Department</b></td>
<td><input type="text" name="Department" size="40"> </td>
</tr>
<tr>
<td align="right"><b>Phone Number 1</b></td>
<td><input type="text" name="Phone1" size="40"> </td>
</tr>
<tr>
<td align="right"><b>Phone Number 2</b></td>
<td><input type="text" name="Phone2" size="40"> </td>
</tr>
<tr>
<td align="right"><b>Cellular</b></td>
<td><input type="text" name="Cellular" size="40"> </td>
</tr>
<tr>
<td align="right"><b>Pager</b></td>
<td><input type="text" name="Pager" size="40"> </td>
</tr>
<tr>
<td align="right"><b>Fax</b></td>
<td><input type="text" name="Fax" size="40"> </td>
</tr>
<tr>
<td align="right"><b>Email</b></td>
<td><input type="text" name="Email" size="40"> </td>
</tr>
<tr>
<td align="right"><b>Details</b></td>
<td><input type="text" name="Details" size="40"> </td>
</tr>
<tr>
<td align="center" colspan="2"><input type="button" name="cmdSubmit" value="Submit"
OnClick="Validate()"> <input type="reset" name="cmdReset" value="Reset"> </td>
</tr>
</table>
<script language="Javascript">
</body>
</html>
<%
Conn.close
%>
|
|

February 22nd, 2004, 05:34 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hey Sinner,
I'm always using this:
<%
Set Conn = Server.CreateObject("ADODB.Connection")
set objRS = Server.CreateObject("ADODB.Recordset")
Conn.Open "DSN=DSNNAME; pwd=Whatever"
<%
sqlTxt = "INSERT INTO Contact (Contact_Name, Department, Phone1, Phone2, Cellular, Pager, Fax, Email, Details) values ('"& request.form("Contact_Name")&"','"& request.form("Department")&"','"& request.form("Phone1")&"','"& request.form("Phone2")&"','"& request.form("Cellular")&"','"& request.form("Pager")&"','"& request.form("Fax")&"','"& request.form("Email")&"','"& request.form("Details") &"')"
Conn.Execute(sqlTxt)
%>
Hope this helps!
Regards
HammR
|
|

February 23rd, 2004, 12:00 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
|
|
This is easy and provided your database is an Access database. MsSql would have a different connection string, but the recordset would be the same.
cn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Databases\Contacts.mdb"
'C:\Databases\Contacts.mdb being the path of your database.
set rs = server.createobject("adodb.recordset")
sql = "select * from Contacts"
rs.open sql, cn, 3, 3
rs.addnew
rs("Contact_Name") = request("Contact_Name")
rs("Department") = request("Department")
rs("Phone1") = request("Phone1")
rs("Phone2") = request("Phone2")
rs("Cellular") = request("Cellular")
rs("Pager") = request("Pager")
rs("Fax") = request("Fax")
rs("Email") = request("Email")
rs("Details") = request("Details")
rs.update
|
|

February 24th, 2004, 08:25 PM
|
|
Authorized User
|
|
Join Date: Feb 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thank you Dave and hammr, I got it going now. I really appreciate your time. Next step is UPDATE and DELETE, same database. I might bug you guys again.
Peace out :D
|
|

February 25th, 2004, 03:18 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
No Problem
|
|

February 25th, 2004, 06:12 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2003
Posts: 171
Thanks: 0
Thanked 1 Time in 1 Post
|
|
You can slightly modify the recordset that I had posted very easily to accomodate an update. That would be much easier than trying to maintain two different recordsets.
Deletes are not much different.
|
|
 |