Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
Form1.cs
Package: Visual.rar [view]
Upload User: yiyuerguo
Upload Date: 2014-09-27
Package Size: 3781k
Code Size: 4k
Category:
CSharp
Development Platform:
Others
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using System.Data.OleDb;
- namespace useDataGrid
- {
- /// <summary>
- /// Summary description for Form1.
- /// </summary>
- public class Form1 : System.Windows.Forms.Form
- {
- private System.Windows.Forms.DataGrid dataGrid1;
- private System.Data.DataSet ds;
- private OleDbDataAdapter da;
- private OleDbCommandBuilder cb;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- public Form1()
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- }
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.dataGrid1 = new System.Windows.Forms.DataGrid();
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
- this.SuspendLayout();
- //
- // dataGrid1
- //
- this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.dataGrid1.DataMember = "";
- this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
- this.dataGrid1.Location = new System.Drawing.Point(8, 8);
- this.dataGrid1.Name = "dataGrid1";
- this.dataGrid1.Size = new System.Drawing.Size(296, 216);
- this.dataGrid1.TabIndex = 0;
- //
- // Form1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(312, 269);
- this.Controls.Add(this.dataGrid1);
- this.Name = "Form1";
- this.Text = "使用DataGrid控件来显示数据";
- this.Load += new System.EventHandler(this.Form1_Load);
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new Form1());
- }
- private void Form1_Load(object sender, System.EventArgs e)
- {
- //创建一个数据链接
- string strCon =@" Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =sample.xls;Extended Properties=Excel 8.0" ;
- OleDbConnection myConn = new OleDbConnection ( strCon ) ;
- string strCom = " SELECT * FROM [Sheet1$] " ;
- myConn.Open ( ) ;
- //打开数据链接,得到一个数据集
- OleDbDataAdapter myCommand = new OleDbDataAdapter ( strCom , myConn ) ;
- //创建一个 DataSet对象
- ds = new DataSet ( ) ;
- //得到自己的DataSet对象
- myCommand.Fill (ds , "[Sheet1$]" ) ;
- //关闭此数据链接
- myConn.Close ( ) ;
- // 把数据显示在DataGrid控件中.
- dataGrid1.DataSource = ds.DefaultViewManager;
- }
- private void dataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
- {
- }
- private void button1_Click(object sender, System.EventArgs e)
- {
- da.Update(ds,"Developer");
- }
- }
- }