<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    kapok

    垃圾桶,嘿嘿,我藏的這么深你們還能找到啊,真牛!

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      455 隨筆 :: 0 文章 :: 76 評(píng)論 :: 0 Trackbacks

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingannotationswithtypeddataset.asp

    Annotations enable you to modify the names of the elements in your typed DataSet without modifying the underlying schema. Modifying the names of the elements in your underlying schema would cause the typed DataSet to refer to objects that do not exist in the data source, as well as losing a reference to the objects that do exist in the data source.

    Using annotations, you can customize the names of objects in your typed DataSet with more meaningful names, making code more readable and your typed DataSet easier for clients to use, while leaving underlying schema intact. For example, the following schema element for the Customers table of the Northwind database would result in a DataRow object name of CustomersRow and a DataRowCollection named Customers.

    <xs:element name="Customers">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="CustomerID" type="xs:string" minOccurs="0" />
        </xs:sequence>
      </xs:complexType>
    </xs:element>

    A DataRowCollection name of Customers is meaningful in client code, but a DataRow name of CustomersRow is misleading because it is a single object. Also, in common scenarios, the object would be referred to without the Row identifier and instead would be simply referred to as a Customer object. The solution is to annotate the schema and identify new names for the DataRow and DataRowCollection objects. Following is the annotated version of the previous schema.

    <xs:element name="Customers" codegen:typedName="Customer" codegen:typedPlural="Customers">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="CustomerID" type="xs:string" minOccurs="0" />
        </xs:sequence>
      </xs:complexType>
    </xs:element>

    Specifying a typedName value of Customer will result in a DataRow object name of Customer. Specifying a typedPlural value of Customers preserves the DataRowCollection name of Customers.

    The following table shows the annotations available for use.

    Annotation Description
    typedName Name of the object.
    typedPlural Name of a collection of objects.
    typedParent Name of the object when referred to in a parent relationship.
    typedChildren Name of the method to return objects from a child relationship.
    nullValue Value if the underlying value is DBNull. See the following table for nullValue annotations. The default is _throw.

    The following table shows the values that can be specified for the nullValue annotation.

    nullValue Description
    Replacement Value Specifies a value to be returned. The returned value must match the type of the element. For example, use nullValue="0" to return 0 for null integer fields.
    _throw Throw an exception. This is the default.
    _null Return a null reference or throw an exception if a primitive type is encountered.
    _empty For strings, return String.Empty, otherwise return an object created from an empty constructor. If a primitive type is encountered, throw an exception.

    The following table shows default values for objects in a typed DataSet and the available annotations.

    Object/Method/Event Default Annotation
    DataTable TableNameDataTable typedPlural
    DataTable Methods NewTableNameRow

    AddTableNameRow

    DeleteTableNameRow

    typedName
    DataRowCollection TableName typedPlural
    DataRow TableNameRow typedName
    DataColumn DataTable.ColumnNameColumn

    DataRow.ColumnName

    typedName
    Property PropertyName typedName
    Child Accessor GetChildTableNameRows typedChildren
    Parent Accessor TableNameRow typedParent
    DataSet Events TableNameRowChangeEvent

    TableNameRowChangeEventHandler

    typedName

    To use typed DataSet annotations, you must include the following xmlns reference in your XML Schema definition language (XSD) schema.

    xmlns:codegen="urn:schemas-microsoft-com:xml-msprop"

    The following is a sample, annotated schema that exposes the Customers table of the Northwind database with a relation to the Orders table included.

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema id="CustomerDataSet" 
          xmlns:codegen="urn:schemas-microsoft-com:xml-msprop"
          xmlns="" 
          xmlns:xs="http://www.w3.org/2001/XMLSchema" 
          xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
      <xs:element name="CustomerDataSet" msdata:IsDataSet="true">
        <xs:complexType>
          <xs:choice maxOccurs="unbounded">
            <xs:element name="Customers" codegen:typedName="Customer" codegen:typedPlural="Customers">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="CustomerID" codegen:typedName="CustomerID" type="xs:string" minOccurs="0" />
                  <xs:element name="CompanyName" codegen:typedName="CompanyName" type="xs:string" minOccurs="0" />
                  <xs:element name="Phone" codegen:typedName="Phone" codegen:nullValue="" type="xs:string" minOccurs="0" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
            <xs:element name="Orders" codegen:typedName="Order" codegen:typedPlural="Orders">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="OrderID" codegen:typedName="OrderID" type="xs:int" minOccurs="0" />
                  <xs:element name="CustomerID" codegen:typedName="CustomerID" codegen:nullValue="" type="xs:string" minOccurs="0" />
                  <xs:element name="EmployeeID" codegen:typedName="EmployeeID" codegen:nullValue="0" type="xs:int" minOccurs="0" />
                  <xs:element name="OrderDate" codegen:typedName="OrderDate" codegen:nullValue="1980-01-01T00:00:00" type="xs:dateTime" minOccurs="0" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:choice>
        </xs:complexType>
        <xs:unique name="Constraint1">
          <xs:selector xpath=".//Customers" />
          <xs:field xpath="CustomerID" />
        </xs:unique>
        <xs:keyref name="CustOrders" refer="Constraint1" codegen:typedParent="Customer" codegen:typedChildren="GetOrders">
          <xs:selector xpath=".//Orders" />
          <xs:field xpath="CustomerID" />
        </xs:keyref>
      </xs:element>
    </xs:schema>

    The following code example uses a strongly typed DataSet created from the sample schema. It uses one DataAdapter to populate the Customers table and another DataAdapter to populate the Orders table. The strongly typed DataSet defines the DataRelations.

    [Visual Basic]
    Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;" & _
                                                       "Initial Catalog=northwind")
    Dim custDA As SqlDataAdapter = New SqlDataAdapter("SELECT CustomerID, CompanyName, Phone FROM Customers", &
                                                      nwindConn)
    Dim orderDA As SqlDataAdapter = New SqlDataAdapter("SELECT OrderID, CustomerID, EmployeeID, OrderDate FROM Orders", &
                                                       nwindConn)
    
    ' Populate a strongly typed DataSet.
    nwindConn.Open()
    Dim custDS As CustomerDataSet = New CustomerDataSet()
    custDA.Fill(custDS, "Customers")
    orderDA.Fill(custDS, "Orders")
    nwindConn.Close()
    
    ' Add a strongly typed event.
    AddHandler custDS.Customers.CustomerChanged, &
               New CustomerDataSet.CustomerChangeEventHandler(AddressOf OnCustomerChanged)
    
    ' Add a strongly typed DataRow.
    Dim newCust As CustomerDataSet.Customer = custDS.Customers.NewCustomer()
    newCust.CustomerID = "NEW01"
    newCust.CompanyName = "My New Company"
    custDS.Customers.AddCustomer(newCust)
    
    ' Navigate the child relation.
    Dim customer As CustomerDataSet.Customer
    Dim order As CustomerDataSet.Order
    
    For Each customer In custDS.Customers
      Console.WriteLine(customer.CustomerID)
      For Each order In customer.GetOrders()
        Console.WriteLine(vbTab & order.OrderID)
      Next
    Next
    
    Private Shared Sub OnCustomerChanged(sender As Object, e As CustomerDataSet.CustomerChangeEvent)
    
    End Sub
    [C#]
    SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind");
    SqlDataAdapter custDA = new SqlDataAdapter("SELECT CustomerID, CompanyName, Phone FROM Customers", nwindConn);
    SqlDataAdapter orderDA = new SqlDataAdapter("SELECT OrderID, CustomerID, EmployeeID, OrderDate FROM Orders", nwindConn);
    
    // Populate a strongly typed DataSet.
    nwindConn.Open();
    CustomerDataSet custDS = new CustomerDataSet();
    custDA.Fill(custDS, "Customers");
    orderDA.Fill(custDS, "Orders");
    nwindConn.Close();
    
    // Add a strongly typed event.
    custDS.Customers.CustomerChanged += new 
      CustomerDataSet.CustomerChangeEventHandler(OnCustomerChanged);
    
    // Add a strongly typed DataRow.
    CustomerDataSet.Customer newCust = custDS.Customers.NewCustomer();
    newCust.CustomerID = "NEW01";
    newCust.CompanyName = "My New Company";
    custDS.Customers.AddCustomer(newCust);
    
    // Navigate the child relation.
    foreach(CustomerDataSet.Customer customer in custDS.Customers)
    {
      Console.WriteLine(customer.CustomerID);
      foreach(CustomerDataSet.Order order in customer.GetOrders())
        Console.WriteLine("\t" + order.OrderID);
    }
    
    protected static void OnCustomerChanged(object sender, CustomerDataSet.CustomerChangeEvent e)
    {
    
    }

    See Also

    Working with a Typed DataSet | Creating and Using DataSets | DataColumnCollection Class | DataSet Class

    posted on 2005-04-12 14:16 笨笨 閱讀(322) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): ALL.NET
    主站蜘蛛池模板: 午夜精品在线免费观看| 久久精品国产亚洲AV果冻传媒 | 日韩在线观看视频免费 | 极品色天使在线婷婷天堂亚洲| 亚洲成人一区二区| 日韩内射激情视频在线播放免费| 久久精品国产亚洲av麻豆图片| 亚洲成AV人网址| 免费国产黄网站在线观看视频| 鲁死你资源站亚洲av| 国产AV无码专区亚洲精品| 成年女人免费视频播放体验区| jyzzjyzz国产免费观看| 亚洲剧场午夜在线观看| 不卡精品国产_亚洲人成在线 | 亚洲国产日韩在线观频| 1000部国产成人免费视频| 一级毛片免费播放试看60分钟| 亚洲国产成人精品无码一区二区 | 亚洲AV乱码一区二区三区林ゆな| 青青青青青青久久久免费观看| 三级网站在线免费观看| 日韩国产精品亚洲а∨天堂免| 久久精品国产亚洲香蕉| 亚洲精品国自产拍在线观看 | 五月天网站亚洲小说| 国产免费久久精品| 中文字幕无码视频手机免费看| 国产黄色免费观看| 亚洲暴爽av人人爽日日碰| 亚洲精品无码不卡| 国产精品V亚洲精品V日韩精品| 好吊妞视频免费视频| 18禁美女黄网站色大片免费观看| 国产精品99爱免费视频| 精品无码专区亚洲| 亚洲熟伦熟女专区hd高清| 亚洲高清美女一区二区三区| 亚洲精品无码专区在线在线播放 | 可以免费看黄的网站| 久久这里只精品国产免费10|