Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2002
    Location
    usa
    Posts
    2

    Arrow Unanswered: Getting the data to the text field in asp.

    Hello!

    I wrote an asp using vbscript. On the page i have some text fields for input/ output.
    I put the connection string in and no error occured. Yet, no records from the table are displayed in the text box, Why?

    Second, When I attempt to move through the records, using a cmdFirst command, i recieve an error.

    The code for the command is:

    Sub cmdFirst_OnClick()
    Me.Recordset.MovePrevious
    End Sub

    What did i miss?

    Help is greatly appreciated.

    JCS.

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    Please post the entire asp page.

  3. #3
    Join Date
    Nov 2002
    Location
    usa
    Posts
    2

    Re: here is the code

    Originally posted by rnealejr
    Please post the entire asp page.

    <%@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>PSMM AddressBook1 -personal contacts
    <H1></H1>
    <% ' to integrate/test this code replace the
    ' Data Source value in the Connection string%>
    <%
    ' connection and recordset variables
    Dim Cnxn, strCnxn
    Dim rsPersonal, strSQLPersonal Contacts
    Dim fld, Err

    ' open connection
    Set Cnxn = Server.CreateObject("ADODB.Connection")
    strCnxn = "Provider='Microsoft.Jet.OLEDB.3.51';Data Source="C:\Documents and Settings\James Snaith\Desktop\Solution3\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 Personal Contacts 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">&nbsp;&nbsp;<INPUT type="button" name="cmdFirst" Value="Show First">&nbsp;&nbsp;<INPUT type="button" name="cmdLast" Value="Show Next">
    <INPUT id="Button1" type="button" value="Delete" name="cmdDelete">
    <TD Align="left">
    &nbsp;
    <TD Align="left">
    <INPUT id="Data1" type="text" size="10" name="Data1"></TD>
    </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">
    Private Sub cmdAdd_Click()
    Data1.Recordset.AddNew
    End Sub

    Private Sub cmdDelete_Click()
    'this may produce an error if you delete the last
    'record or the only record in the recordset
    Data1.Recordset.Delete
    Data1.Recordset.MoveNext
    End Sub


    Private Sub cmdUpdate_Click()
    Data1.UpdateRecord
    Data1.Recordset.Bookmark = Data1.Recordset.LastModified
    End Sub

    Private Sub Data1_Reposition()
    Screen.MousePointer = vbDefault
    On Error Resume Next
    'This will display the current record position
    'for dynasets and snapshots
    Data1.Caption = "Record: " & (Data1.Recordset.AbsolutePosition + 1)
    'for the table object you must set the index property when
    'the recordset gets created and use the following line
    'Data1.Caption = "Record: " & (Data1.Recordset.RecordCount * (Data1.Recordset.PercentPosition * 0.01)) + 1
    End Sub

    Private Sub Data1_Validate(Action As Integer, Save As Integer)
    'This is where you put validation code
    'This event gets called when the following actions occur
    Select Case Action
    Case vbDataActionMoveFirst
    Case vbDataActionMovePrevious
    Case vbDataActionMoveNext
    Case vbDataActionMoveLast
    Case vbDataActionAddNew
    Case vbDataActionUpdate
    Case vbDataActionDelete
    Case vbDataActionFind
    Case vbDataActionBookmark
    Case vbDataActionClose
    End Select
    Screen.MousePointer = default
    End Sub


    </SCRIPT>
    <!-- EndAddNewVBS -->
    </BODY>
    </HTML>

  4. #4
    Join Date
    Feb 2002
    Posts
    2,232
    Did you catch the following typo:

    rs.PersonalContactsActiveConnection = Cnxn

    should be

    rsPersonalContacts.ActiveConnection = Cnxn

    Also, what error are you receiving ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •