<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<head>
<title>SqlCommand Example</title>
<link rel="stylesheet" href="/shared/netdemos.css">
<script language="C#" runat="server" src="/shared/fetchData_sql.cs" />
<script language="C#" runat="server">
string html;
protected void Page_Load ( Object src, EventArgs e ) {
// connect to data source
SqlConnection myConn = new SqlConnection ( getConnection ( "aspnet" ) );
// define the command query
string query = "SELECT * FROM Authors";
// initialize command object with the specified query and connection
SqlCommand myCmd = new SqlCommand ( query, myConn );
// open the data connection
myConn.Open ( );
// retrieve properties of the command object
html += "<table cellspacing=1 class=data width=90%>";
html += "<tr><td><b>CommandText</b></td>";
html += "<td>" + myCmd.CommandText + "</td></tr>";
html += "<tr><td><b>CommandTimeout</b></td>";
html += "<td>" + myCmd.CommandTimeout + "</td></tr>";
html += "<tr><td><b>CommandType</b></td>";
html += "<td>" + myCmd.CommandType + "</td></tr>";
html += "<tr><td><b>Connection</b></td>";
html += "<td>" + myCmd.Connection + "</td></tr>";
html += "<tr><td><b>Parameters</b></td>";
html += "<td>" + myCmd.Parameters + "</td></tr>";
html += "<tr><td><b>Transaction</b></td>";
html += "<td>" + myCmd.Transaction + "</td></tr>";
html += "<tr><td><b>UpdatedRowSource</b></td>";
html += "<td>" + myCmd.UpdatedRowSource + "</td></tr>";
html += "</table>";
// close the data connection
myConn.Close ( );
}
</script>
</head>
<body>
<!-- #include virtual="~/shared/top.inc" -->
<div class="header"><h2>ADO.NET Primer: <b>SqlCommand</b> Example</h2></div>
<hr size=1 width=92%>
<center>
<p><i>Properties of current <b>SqlCommand</b> object</i></p>
<%= html %>
</center>
<hr size=1 width=92%>
<!-- #include virtual="~/shared/viewsrc.inc" -->
</body>
</html>