ASP.NET Tutorial/ADO.net Database/DataTableReader — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 11:56, 26 мая 2010

Usage of in-memory, disconnected readers

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 
    Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Create Data Reader</title>
</head>
<body>
    <div id="pageContent">
        <form id="form1" runat="server">
            <asp:Label runat="server" ID="Label1"></asp:Label>
        </form>
    </div>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    DataSet data = new DataSet();
    SqlDataAdapter adapter = new SqlDataAdapter(
      "SELECT * FROM employees;SELECT * FROM customers",
      ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
    adapter.Fill(data);
    DataTableReader reader = data.CreateDataReader();
        StringBuilder builder = new StringBuilder();
    do
    {
      while (reader.Read())
                builder.AppendFormat("{0} <br>", reader[1]);
            builder.Append("<hr>");
    } while (reader.NextResult());
    reader.Close();
        Label1.Text = builder.ToString();
    }
}