當前位置: 首頁>>代碼示例>>C#>>正文


C# DataViewManager.DataViewSettings屬性代碼示例

本文整理匯總了C#中System.Data.DataViewManager.DataViewSettings屬性的典型用法代碼示例。如果您正苦於以下問題:C# DataViewManager.DataViewSettings屬性的具體用法?C# DataViewManager.DataViewSettings怎麽用?C# DataViewManager.DataViewSettings使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。


在下文中一共展示了DataViewManager.DataViewSettings屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Form1

//引入命名空間
using System;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Windows.Forms;

class Form1 : Form {
    public Form1() {
        InitializeComponent();
    }

    private void getData_Click(object sender, EventArgs e) {
        string orders = "SELECT * FROM Orders";
        string customers = "SELECT * FROM Customers";

        using (SqlConnection con = new SqlConnection("northwind ConnectionString")) {

            SqlDataAdapter da = new SqlDataAdapter(orders, con);

            DataSet ds = new DataSet();

            da.Fill(ds, "Orders");

            da = new SqlDataAdapter(customers, con);

            da.Fill(ds, "Customers");

            ds.Relations.Add("CustomerOrders",
                ds.Tables["Customers"].Columns["CustomerID"],
                ds.Tables["Orders"].Columns["CustomerID"]);

            DataViewManager dvm = new DataViewManager(ds);

            dvm.DataViewSettings["Customers"].RowFilter = "Country='UK'";

            dataGrid.SetDataBinding(dvm, "Customers");

        }

    }
    private void InitializeComponent() {
        this.getData = new System.Windows.Forms.Button();
        this.dataGrid = new System.Windows.Forms.DataGrid();
        this.SuspendLayout();
        // 
        // getData
        // 
        this.getData.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
        this.getData.Location = new System.Drawing.Point(684, 558);
        this.getData.Name = "getData";
        this.getData.TabIndex = 0;
        this.getData.Text = "Get Data";
        this.getData.Click += new System.EventHandler(this.getData_Click);
        // 
        // dataGrid
        // 
        this.dataGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                    | System.Windows.Forms.AnchorStyles.Left)
                    | System.Windows.Forms.AnchorStyles.Right)));
        this.dataGrid.Location = new System.Drawing.Point(13, 13);
        this.dataGrid.Name = "dataGrid";
        this.dataGrid.Size = new System.Drawing.Size(745, 534);
        this.dataGrid.TabIndex = 1;
        // 
        // Form1
        // 
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.ClientSize = new System.Drawing.Size(771, 593);
        this.Controls.Add(this.dataGrid);
        this.Controls.Add(this.getData);
        this.Name = "Form1";
        this.Text = "Form1";
        this.ResumeLayout(false);

    }



    private System.Windows.Forms.Button getData;
    private System.Windows.Forms.DataGrid dataGrid;

    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}
開發者ID:C#程序員,項目名稱:System.Data,代碼行數:89,代碼來源:DataViewManager.DataViewSettings


注:本文中的System.Data.DataViewManager.DataViewSettings屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。