|
 |
access thread: MDB Connection
Message #1 by "jcs" <james@p...> on Fri, 22 Nov 2002 08:38:35 -0800
|
|
Good Mornin'
I have attempted several times to connect my database (PSMM.mdb) to a project file.
With no success, frustration is mounting.
The Page created is an ASP.
The Table Header <TH> displays correctly, yet no table shows the existing records.
The Table in the Database is named= PersonalContacts.
On the lower part of the page there is an area to add a new record to that database.
The fields are in place, buttons in place, yet when i fill those fields at runtime, the data is not added to the database.
The Code is below.
Please help, time is of the essence.
///////////////////////////////////////////////////////////////////////////////////
<%@Language = VBScript %>
<HTML>
<HEAD>
<TITLE>AddressBook1</TITLE>
<!-- BeginAddNewVBS -->
<%' use this meta tag instead of adovbs.inc%>
<!--METADATA TYPE="typelib" uuid="00000205-0000-0010-8000-00AA006D2EA4" -->
<!--
body {
font-family: 'BankGothic Md BT';
BACKGROUND-COLOR:#253659;
COLOR:white;
}
TH {
background-color: #008080;
font-family: 'BankGothic Md BT';
font-size: xx-small;
color: white;
}
TD {
text-align: left;
background-color: #253659;
font-family: 'Arial Narrow','Arial',sans-serif;
font-size: xx-small;
}
-->
</STYLE>
</HEAD>
<BODY bgcolor="#253659">
<p><FONT color="#ffcc66">PSMM AddressBook1 -personal contacts</FONT>
<H1></H1>
<% ' to integrate/test this code replace the
' Data Source value in the Connection string%>
<%
' connection and recordset variables
Dim Cnxn, strCnxn
Dim rsPersonalContacts, strSQLPersonal Contacts
Dim fld, Err
' open connection
Set Cnxn = Server.CreateObject("ADODB.Connection")
strCnxn = "Provider='Microsoft.Jet.OLEDB.3.51';Data Source="C:\PSMM\PSMM.mdb" & _
Request.ServerVariables("SERVER_NAME") & ";" & _
"Integrated Security='SSPI';Initial Catalog='PSMM';"
Cnxn.Open strCnxn
' create and open Recordset using object refs
Set rsPersonalContacts = Server.CreateObject("ADODB.Recordset")
strSQLPersonalContacts = "Personal Contacts"
rs.PersonalContactsActiveConnection = Cnxn
rsPersonalContacts.CursorLocation = adUseClient
rsPersonalContacts.CursorType = adOpenKeyset
rsPersonalContacts.LockType = adLockOptimistic
rsPersonalContacts.Source = strSQLPersonalContacts
rsPersonalContacts.Open
'If this is first time page is open, Form collection
'will be empty when data is entered. run AddNew method
If Not IsEmpty(Request.Form) Then
If Not Request.Form("Last Name") = "" Then
rsPersonalContacts.AddNew
rsPersonalContacts("LastName") = Request.Form("Last Name")
rsPersonalContacts("FirstName") = Request.Form("First Name") & _
" " & Request.Form("Last Name")
rsPersonalContacts("Street") = Request.Form("Street")
rsPersonalContacts("City") = Request.Form("City")
rsPersonalContacts("State") = Request.Form("State")
rsPersonalContacts("Postal Code") = Request.Form("Postal Code")
rsPersonalContacts("Email") = Request.Form("Email")
rsPersonalContacts("Telephone") = Request.Form("Telephone")
rsPersonalContacts("Notes") = Request.Form("Notes")
rsPersonalContacts.Update
' check for errors
If Cnxn.Errors.Count > 0 Then
For Each Err In Cnxn.Errors
Response.Write("Error " & Err.SQLState & ": " & _
Err.Description & " | " & Err.NativeError)
Next
Cnxn.Errors.Clear
rsPersonalContacts.CancelUpdate
End If
'On Error GoTo 0
rsPersonalContacts.MoveFirst
End If
End If
%>
<TABLE CELLPADDING="5" BORDER="1" ALIGN="left" height="8">
<!-- BEGIN column header row for PersonalContacts Table-->
<TR>
<TH>
Last Name</TH>
<TH>
First Name</TH>
<TH>
Street</TH>
<TH>
City</TH>
<TH>
State | Province</TH>
<TH>
Postal Code</TH>
<TH>
Email Address</TH>
<TH>
Telephone</TH>
<TH>
Notes</TH>
</TR>
<% ' show the data
Do Until rsCustomers.EOF
Response.Write("<TR>")
Response.Write("<TD>" & rsPersonalContacts("LastName")& "</TD>")
Response.Write("<TD>" & rsPersonalContacts("FirstName") & "</TD>")
Response.Write("<TD>" & rsPersonalContacts("Street") & "</TD>")
Response.Write("<TD>" & rsPersonalContacts("City") & "</TD>")
Response.Write("<TD>" & rsPersonalContacts("State") & "</TD>")
Response.Write("<TD>" & rsPersonalContacts("PostalCode") & "</TD>")
Response.Write("<TD>" & rsPersonalContacts("Email") & "</TD>")
Response.Write("<TD>" & rsPersonalContacts("Telephone") & "</TD>")
Response.Write("<TD>" & rsPersonalContacts("Notes") & "</TD>")
Response.Write("</TR>")
rsPersonalContacts.MoveNext
Loop
%>
</TABLE>
<BR>
<HR>
<!--
Form to enter new record posts variables
back to this page
-->
<FORM Method="post" Action="AddressBook1.asp" Name="Form">
<TABLE height="282">
<TR>
<TD>Last Name:</TD>
<TD><INPUT Size="50" Name="LastName"></TD>
</TR>
<TR>
<TD>
First Name:</TD>
<TD><INPUT Size="50" Name="FirstName"></TD>
</TR>
<TR>
<TD>Telephone:</TD>
<TD><INPUT Size="50" Name="Street"></TD>
</TR>
<TR>
<TD>City:</TD>
<TD><INPUT Size="50" Name="City"></TD>
</TR>
<TR>
<TD>State | Province:</TD>
<TD><INPUT Size="50" Name="State"></TD>
</TR>
<TR>
<TD>Postal Code:</TD>
<TD><INPUT Size="50" Name="Postal Code"></TD>
</TR>
<TR>
<TD>Emal:</TD>
<TD><INPUT Size="50" Name="Email"></TD>
</TR>
<TR>
<TD>Telephone:</TD>
<TD><INPUT Size="50" Name="Telephone"></TD>
</TR>
<TR>
<TD>Notes:</TD>
<TD><INPUT Size="50" Name="Notes"></TD>
</TR>
<TR>
<TD Align="left"><INPUT Type="submit" Value="Add New">
<TD Align="left"><INPUT Type="reset" Value="Reset Form"> <INPUT type="button"
name="cmdFirst" Value="Show First"> <INPUT type="button" name="cmdLast" Value="Show Next">
</TR>
</TABLE>
</FORM>
<%
' show connection
Response.Write("Following is the connection string: <br><br>")
Response.Write(Cnxn)
' Clean up.
If rsPersonalContacts.State = adStateOpen then
rsPersonalContacts.Close
End If
If Cnxn.State = adStateOpen then
Cnxn.Close
End If
Set rsPersonalContacts=Nothing
Set Cnxn=Nothing
Set fld=Nothing
%>
<SCRIPT Language="VBScript">
Sub Form_OnSubmit
MsgBox "PSMM is Now Adding New Record to AddressBook1 -personal contacts"
End Sub
Sub cmdFirst_OnClick
Me.Recordset.MovePrevious
End Sub
Sub cmdLast_OnClick
Me.Recordset.MoveNext
End Sub
</SCRIPT>
<!-- EndAddNewVBS -->
</BODY>
</HTML>
//////////////////////////////////////////////////////////////////////////////////
Message #2 by "Donald Roberts" <Skipmeok@a...> on Fri, 22 Nov 2002 20:41:35
|
|
> Good Mornin'
I have attempted several times to connect my database (PSMM.mdb) to a
project file.
With no success, frustration is mounting.
The Page created is an ASP.
The Table Header <TH> displays correctly, yet no table shows the existing
records.
The Table in the Database is named= PersonalContacts.
On the lower part of the page there is an area to add a new record to that
database.
The fields are in place, buttons in place, yet when i fill those fields at
runtime, the data is not added to the database.
The Code is below.
Please help, time is of the essence.
///////////////////////////////////////////////////////////////////////////
////////
<%@Language = VBScript %>
<HTML>
<HEAD>
<TITLE>AddressBook1</TITLE>
<!-- BeginAddNewVBS -->
<%' use this meta tag instead of adovbs.inc%>
<!--METADATA TYPE="typelib" uuid="00000205-0000-0010-8000-00AA006D2EA4" -
->
<!--
body {
font-family: 'BankGothic Md BT';
BACKGROUND-COLOR:#253659;
COLOR:white;
}
TH {
background-color: #008080;
font-family: 'BankGothic Md BT';
font-size: xx-small;
color: white;
}
TD {
text-align: left;
background-color: #253659;
font-family: 'Arial Narrow','Arial',sans-serif;
font-size: xx-small;
}
-->
</STYLE>
</HEAD>
<BODY bgcolor="#253659">
<p><FONT color="#ffcc66">PSMM AddressBook1 -personal contacts</FONT>
<H1></H1>
<% ' to integrate/test this code replace the
' Data Source value in the Connection string%>
<%
' connection and recordset variables
Dim Cnxn, strCnxn
Dim rsPersonalContacts, strSQLPersonal Contacts
Dim fld, Err
' open connection
Set Cnxn = Server.CreateObject("ADODB.Connection")
strCnxn = "Provider='Microsoft.Jet.OLEDB.3.51';Data
Source="C:\PSMM\PSMM.mdb" & _
Request.ServerVariables("SERVER_NAME") & ";" & _
"Integrated Security='SSPI';Initial Catalog='PSMM';"
Cnxn.Open strCnxn
' create and open Recordset using object refs
Set rsPersonalContacts = Server.CreateObject("ADODB.Recordset")
strSQLPersonalContacts = "Personal Contacts"
rs.PersonalContactsActiveConnection = Cnxn
rsPersonalContacts.CursorLocation = adUseClient
rsPersonalContacts.CursorType = adOpenKeyset
rsPersonalContacts.LockType = adLockOptimistic
rsPersonalContacts.Source = strSQLPersonalContacts
rsPersonalContacts.Open
'If this is first time page is open, Form collection
'will be empty when data is entered. run AddNew method
If Not IsEmpty(Request.Form) Then
If Not Request.Form("Last Name") = "" Then
rsPersonalContacts.AddNew
rsPersonalContacts("LastName") = Request.Form("Last Name")
rsPersonalContacts("FirstName") = Request.Form("First
Name") & _
" " & Request.Form("Last Name")
rsPersonalContacts("Street") = Request.Form("Street")
rsPersonalContacts("City") = Request.Form("City")
rsPersonalContacts("State") = Request.Form("State")
rsPersonalContacts("Postal Code") = Request.Form("Postal Code")
rsPersonalContacts("Email") = Request.Form("Email")
rsPersonalContacts("Telephone") = Request.Form("Telephone")
rsPersonalContacts("Notes") = Request.Form("Notes")
rsPersonalContacts.Update
' check for errors
If Cnxn.Errors.Count > 0 Then
For Each Err In Cnxn.Errors
Response.Write("Error " & Err.SQLState & ": " & _
Err.Description & " | " & Err.NativeError)
Next
Cnxn.Errors.Clear
rsPersonalContacts.CancelUpdate
End If
'On Error GoTo 0
rsPersonalContacts.MoveFirst
End If
End If
%>
<TABLE CELLPADDING="5" BORDER="1" ALIGN="left" height="8">
<!-- BEGIN column header row for PersonalContacts Table-->
<TR>
<TH>
Last Name</TH>
<TH>
First Name</TH>
<TH>
Street</TH>
<TH>
City</TH>
<TH>
State | Province</TH>
<TH>
Postal Code</TH>
<TH>
Email Address</TH>
<TH>
Telephone</TH>
<TH>
Notes</TH>
</TR>
<% ' show the data
Do Until rsCustomers.EOF
Response.Write("<TR>")
Response.Write("<TD>" & rsPersonalContacts("LastName")
& "</TD>")
Response.Write("<TD>" & rsPersonalContacts("FirstName")
& "</TD>")
Response.Write("<TD>" & rsPersonalContacts("Street") & "</TD>")
Response.Write("<TD>" & rsPersonalContacts("City") & "</TD>")
Response.Write("<TD>" & rsPersonalContacts("State") & "</TD>")
Response.Write("<TD>" & rsPersonalContacts("PostalCode")
& "</TD>")
Response.Write("<TD>" & rsPersonalContacts("Email") & "</TD>")
Response.Write("<TD>" & rsPersonalContacts("Telephone")
& "</TD>")
Response.Write("<TD>" & rsPersonalContacts("Notes") & "</TD>")
Response.Write("</TR>")
rsPersonalContacts.MoveNext
Loop
%>
</TABLE>
<BR>
<HR>
<!--
Form to enter new record posts variables
back to this page
-->
<FORM Method="post" Action="AddressBook1.asp" Name="Form">
<TABLE height="282">
<TR>
<TD>Last Name:</TD>
<TD><INPUT Size="50" Name="LastName"></TD>
</TR>
<TR>
<TD>
First Name:</TD>
<TD><INPUT Size="50" Name="FirstName"></TD>
</TR>
<TR>
<TD>Telephone:</TD>
<TD><INPUT Size="50" Name="Street"></TD>
</TR>
<TR>
<TD>City:</TD>
<TD><INPUT Size="50" Name="City"></TD>
</TR>
<TR>
<TD>State | Province:</TD>
<TD><INPUT Size="50" Name="State"></TD>
</TR>
<TR>
<TD>Postal Code:</TD>
<TD><INPUT Size="50" Name="Postal Code"></TD>
</TR>
<TR>
<TD>Emal:</TD>
<TD><INPUT Size="50" Name="Email"></TD>
</TR>
<TR>
<TD>Telephone:</TD>
<TD><INPUT Size="50" Name="Telephone"></TD>
</TR>
<TR>
<TD>Notes:</TD>
<TD><INPUT Size="50" Name="Notes"></TD>
</TR>
<TR>
<TD Align="left"><INPUT Type="submit" Value="Add New">
<TD Align="left"><INPUT Type="reset" Value="Reset
Form"> <INPUT type="button" name="cmdFirst" Value="Show
First"> <INPUT type="button" name="cmdLast" Value="Show Next">
</TR>
</TABLE>
</FORM>
<%
' show connection
Response.Write("Following is the connection string: <br><br>")
Response.Write(Cnxn)
' Clean up.
If rsPersonalContacts.State = adStateOpen then
rsPersonalContacts.Close
End If
If Cnxn.State = adStateOpen then
Cnxn.Close
End If
Set rsPersonalContacts=Nothing
Set Cnxn=Nothing
Set fld=Nothing
%>
<SCRIPT Language="VBScript">
Sub Form_OnSubmit
MsgBox "PSMM is Now Adding New Record to AddressBook1 -personal
contacts"
End Sub
Sub cmdFirst_OnClick
Me.Recordset.MovePrevious
End Sub
Sub cmdLast_OnClick
Me.Recordset.MoveNext
End Sub
</SCRIPT>
<!-- EndAddNewVBS -->
</BODY>
</HTML>
///////////////////////////////////////////////////////////////////////////
///////
|
|
 |