Answers for Day 12

IOTA^_^    

Sams Teach Yourself ASP.NET in 21 Days, Second Edition
By Chris Payne
Table of Contents
Appendix A.  Answers to Quiz Questions


Quiz

1:

Specify a SQL statement to create an empty stored procedure (one that doesn't execute any SQL statement) that accepts one input parameter and one output parameter of your choice.

A1:

 CREATE PROCEDURE SelectIDFromName @Input varchar, @Output int OUTPUT AS 
2:

What are the four parameter directions?

A1:

Input, Output, InputOutput, and ReturnValue.

3:

True or false: You use output parameters if you want to return multiple rows of data.

A1:

False. Generally, output parameters are used for queries that return single values.

4:

Will the following code work?

 Response.Write("ID = " & objCmd.Parameters("@ID"). _    Value.ToString()) objReader.Close() 
A1:

No, because output parameters aren't returned until DataReader is closed.

5:

What's the difference between XPathNavigator and XmlDocument?

A1:

XPathNavigator provides dynamic node loading and supports XPath queries and XSL transforms. The XmlDocument loads an entire node tree upon opening an XML file, and it doesn't support XPath queries or XSL Transforms.

6:

What is an XSL stylesheet used for, and how is it related to XPath queries?

A1:

An XSL stylesheet is used to format XML data into a new structured document. It specifies nodes in an XML document to be formatted, which are retrieved by dynamically generated XPath queries.

7:

How do you return data from an XSL transform with XmlReader? With XmlTextWriter?

A1:

With XmlReader:

 objReader = objXslT.Transform(objNav, nothing) 

With XmlTextWriter:

 objXslT.Transform(objNav, nothing, objWriter) 

Exercise

Q1:

Create a stored procedure that inserts a new row into your tblUsers table using parameters. Build an ASP.NET page that allows users to enter this data, and execute this procedure with parameters.

A1:

The code for the stored procedure (in Access) is as follows:

 1:    INSERT INTO tblUsers ( FirstName, LastName, Address, 2:       City, State, Zip, Phone ) 3:    VALUES (@FirstName, @LastName, @Address, 4:       @City, @state, @Zip, @Phone) 

The code for the ASP.NET page is as follows:

 1:    <%@ Page Language="VB" %> 2:    <%@ Import Namespace="System.Data" %> 3:    <%@ Import Namespace="System.Data.OleDb" %> 4: 5:    <script runat="server"> 6:       'declare connection 7:       dim Conn as new OleDbConnection("Provider=" & _ 8:                "Microsoft.Jet.OLEDB.4.0;" & _ 9:                "Data Source=c:\ASPNET\data\banking.mdb") 10: 11:       sub InsertData(Sender as Object, e as EventArgs) 12:          dim objCmd as OleDbCommand = new OleDbCommand _ 13:             ("InsertUser", Conn) 14:          objCmd.CommandType = CommandType.StoredProcedure 15: 16:          dim objParam as OleDbParameter 17:          objParam = objCmd.Parameters.Add("@FirstName", _ 18:             OleDbType.BSTR) 19:          objParam.Direction = ParameterDirection.Input 20:          objParam.Value = tbFName.Text 21: 22:          objParam = objCmd.Parameters.Add("@LastName", _ 23:             OleDbType.BSTR) 24:          objParam.Direction = ParameterDirection.Input 25:          objParam.Value = tbLName.Text 26: 27:          objParam = objCmd.Parameters.Add("@Address", _ 28:             OleDbType.BSTR) 29:          objParam.Direction = ParameterDirection.Input 30:          objParam.Value = tbAddress.Text 31: 32:          objParam = objCmd.Parameters.Add("@City", _ 33:             OleDbType.BSTR) 34:          objParam.Direction = ParameterDirection.Input 35:          objParam.Value = tbCity.Text 36: 37:          objParam = objCmd.Parameters.Add("@State", _ 38:             OleDbType.BSTR) 39:          objParam.Direction = ParameterDirection.Input 40:          objParam.Value = tbState.Text 41: 42:          objParam = objCmd.Parameters.Add("@Zip", _ 43:             OleDbType.BSTR) 44:          objParam.Direction = ParameterDirection.Input 45:          objParam.Value = tbZip.Text 46: 47:          objParam = objCmd.Parameters.Add("@Phone", _ 48:             OleDbType.BSTR) 49:          objParam.Direction = ParameterDirection.Input 50:          objParam.Value = tbPhone.Text 51: 52:          try 53:             objCmd.Connection.Open() 54:             objCmd.ExecuteNonQuery 55:          catch ex as OleDbException 56:             lblMessage.Text = ex.Message 57:          end try 58: 59:          objCmd.Connection.Close() 60:          lblMessage.Text = "User successfully added." 61:       end sub 62:    </script> 63: 64:    <html><body> 65:       <form runat="server"> 66:          <asp:Label  runat="server" 67:             maintainstate=false /><br> 68:          <asp:Panel  runat="server"> 69:             <table> 70:             <tr> 71:                <td width="100" valign="top"> 72:                   First and last name: 73:                </td> 74:                <td width="300" valign="top"> 75:                   <asp:TextBox  runat="server" /> 76:                   <asp:TextBox  runat="server" /> 77:                </td> 78:             </tr> 79:             <tr> 80:                <td valign="top"> 81:                   Address: 82:                </td> 83:                <td valign="top"> 84:                   <asp:TextBox  85:                      runat="server" /> 86:                </td> 87:             </tr> 88:             <tr> 89:                <td valign="top"> 90:                   City, State, ZIP: 91:                </td> 92:                <td valign="top"> 93:                   <asp:TextBox  94:                      runat="server" />, 95:                   <asp:TextBox  runat="server" 96:                      size=2 />&nbsp; 97:                   <asp:TextBox  runat="server" 98:                      size=5 /> 99:                </td> 100:             </tr> 101:             <tr> 102:                <td valign="top"> 103:                   Phone: 104:                </td> 105:                <td valign="top"> 106:                   <asp:TextBox  runat="server" 107:                      size=11 /><p> 108:                </td> 109:             </tr> 110:             <tr> 111:                <td colspan="2" valign="top" align="right"> 112:                   <asp:Button  runat="server" 113:                      text="Add" 114:                      OnClick="InsertData" /> 115:                </td> 116:             </tr> 117:             </table> 118:          </asp:Panel> 119:       </form> 120:    </body></html> 


    IOTA^_^    
    Top


    Sams Teach Yourself ASP. NET in 21 Days
    Sams Teach Yourself ASP.NET in 21 Days (2nd Edition)
    ISBN: 0672324458
    EAN: 2147483647
    Year: 2003
    Pages: 307
    Authors: Chris Payne

    Similar book on Amazon

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net