本文整理汇总了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;
}
}