- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
Form1.cs
资源名称:Visual.rar [点击查看]
上传用户:yiyuerguo
上传日期:2014-09-27
资源大小:3781k
文件大小:4k
源码类别:
C#编程
开发平台:
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");
- }
- }
- }