本文整理匯總了C#中System.Data.DataViewManager.CreateDataView方法的典型用法代碼示例。如果您正苦於以下問題:C# DataViewManager.CreateDataView方法的具體用法?C# DataViewManager.CreateDataView怎麽用?C# DataViewManager.CreateDataView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了DataViewManager.CreateDataView方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DataViewManagerDemo
//引入命名空間
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
public class DataViewManagerDemo : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
public DataViewManagerDemo()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 8);
this.dataGrid1.Size = new System.Drawing.Size(448, 328);
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(480, 341);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.dataGrid1});
this.Load += new System.EventHandler(this.DataViewManagerDemo_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.Run(new DataViewManagerDemo());
}
private void DataViewManagerDemo_Load(object sender, System.EventArgs e)
{
string ConnectionString ="Integrated Security=SSPI;Initial Catalog=Northwind;Data Source=localhost;";
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();
DataSet ds = new DataSet("Orders");
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Orders", conn);
adapter.Fill(ds, "Orders");
DataViewManager dvm = new DataViewManager(ds);
dvm.DataViewSettings["Orders"].RowFilter = "EmployeeID = 4";
dvm.DataViewSettings["Orders"].Sort = "ShippedDate ASC";
DataView dataView1 = dvm.CreateDataView(ds.Tables["Orders"]);
dataGrid1.DataSource = dataView1;
}
}