Thread: Listing 12-13
View Single Post
  #10 (permalink)  
Old June 14th, 2011, 02:49 PM
flashmanTom flashmanTom is offline
Authorized User
Points: 222, Level: 4
Points: 222, Level: 4 Points: 222, Level: 4 Points: 222, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2007
Location: Phoenix, AZ, USA.
Posts: 48
Thanks: 4
Thanked 0 Times in 0 Posts
Default Dataless Page

I tried what you suggested, but I am getting a page with no information on it. Here is my code:

Code:
<%@PageLanguage="C#" %>
<%@ImportNamespace="System.Data" %>
<%@ImportNamespace="System.Data.SqlClient" %>
<%@ImportNamespace="System.Configuration" %>
<%@ImportNamespace="System.Threading" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<scriptrunat="server">
SqlCommand Command = newSqlCommand();
IAsyncResult AsyncResult;
protectedvoid Page_Load(object sender, EventArgs e)
{
SqlConnection DBCon;
DBCon = newSqlConnection();
DBCon.ConnectionString =
ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
Command.CommandText = " Select Top 5 customers.companyname, customers.contactname, " +
" orders.orderid,orders.orderdate, " +
" orders.requireddate, orders.shippeddate" +
" from orders, customers " +
" where orders.customerid=customers.customerid " +
" order by customers.companyname,customers.contactname";
Command.CommandType = CommandType.Text;
Command.Connection = DBCon;
DBCon.Open();
AsyncResult = Command.BeginExecuteReader(newAsyncCallback(CBMethod), CommandBehavior.CloseConnection);
Thread.Sleep(5000);
DBCon.Close();
}
publicvoid CBMethod(IAsyncResult ar)
{
SqlDataReader OrdersReader;
OrdersReader = Command.EndExecuteReader(AsyncResult);
gvOrders.DataSource = OrdersReader;
gvOrders.DataBind();
}
</script>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:GridViewID="gvOrders"runat="server"AutoGenerateColumns="False"Width="100%">
<Columns>
<asp:BoundFieldDataField="CompanyName"HeaderText="Company Name"/>
<asp:BoundFieldDataField="ContactName"HeaderText="Contact Name"/>
<asp:BoundFieldDataField="OrderDate"DataFormatString="{0:d}"HeaderText="Order Date"/>
<asp:BoundFieldDataField="RequiredDate"DataFormatString="{0:d}"HeaderText="Required Date"/>
<asp:BoundFieldDataField="ShippedDate"HeaderText="Shipped Date"/>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Any help will be greatly appreciated

Tom
__________________
Thomas G Magaro
Reply With Quote