Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 22nd, 2004, 12:27 PM
Authorized User
 
Join Date: Feb 2004
Location: , , Canada.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to sinner
Default 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

%>


Reply With Quote
  #2 (permalink)  
Old February 22nd, 2004, 04:34 PM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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



Reply With Quote
  #3 (permalink)  
Old February 22nd, 2004, 11:00 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Minneapolis, MN, USA.
Posts: 171
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #4 (permalink)  
Old February 24th, 2004, 07:25 PM
Authorized User
 
Join Date: Feb 2004
Location: , , Canada.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to sinner
Default

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

Reply With Quote
  #5 (permalink)  
Old February 25th, 2004, 02:18 PM
Authorized User
 
Join Date: Dec 2003
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No Problem

Reply With Quote
  #6 (permalink)  
Old February 25th, 2004, 05:12 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Minneapolis, MN, USA.
Posts: 171
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding records to db djobes31770 VB Databases Basics 3 November 27th, 2007 08:27 AM
Adding Records with VBA rohit_ghosh Access VBA 7 June 22nd, 2007 05:05 AM
adding multiple records Vince_421 VB Databases Basics 4 February 28th, 2007 06:22 AM
Adding records to sql database jdsflash ASP.NET 1.0 and 1.1 Basics 1 May 18th, 2006 10:37 PM
Adding records to Tables lgpatterson Access VBA 6 March 20th, 2005 06:23 AM



All times are GMT -4. The time now is 01:38 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.