恩 都是通过ado.net ole db
解决方案 »
- 求助:谁能帮我解释下下面代码的用法,最好说一下另存为的流程
- C# DB2Adpter调用DB2 Package中存储过程的问题!!!!!
- 如何取得MenuStrip下的所有ToolStripMenuItem对象
- 在从服务器接收结果时发生传输级错误。 (provider: TCP 提供程序, error: 0 - 信号灯超时时间已到)
- 如何获得鼠标在form中移动时的坐标?
- 请问高手:如何在安装程序中让用户输入密码并保存起来?
- .cs文件如何在.aspx调用!?
- 在一些网站看到用户注册成功后,就会收到相应的注册信息,这个用c#怎么实现?
- 请教:用C#复制EXCEL中数据出错
- .net安装问题
- 我想删除DataGrid中的一行,该怎么做?
- delphi7---> delphi 2005 的问题
txt文件当然只能自己读写了。
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = e:\\bj.xls;Extended Properties=Excel 8.0" ;
myConn = new OleDbConnection( strCon ) ;
string sql="select * from [Sheet1$]";//默认的,自己看他的工作簿叫什么名字............................
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
using System.Data.OleDb ;
public class Form1 : Form
{
private Button button1 ;
private System.Data.DataSet myDataSet ;
private DataGrid DataGrid1 ;
private System.ComponentModel.Container components = null ;
public Form1 ( )
{
//初始化窗体中的各个组件
InitializeComponent ( ) ;
//打开数据链接,得到数据集
GetConnect ( ) ;
}
//清除程序中使用过的资源
protected override void Dispose ( bool disposing )
{
if ( disposing )
{
if ( components != null )
{
components.Dispose ( ) ;
}
}
base.Dispose ( disposing ) ;
}
private void GetConnect ( )
{
//创建一个数据链接
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = c:\\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对象
myDataSet = new DataSet ( ) ;
//得到自己的DataSet对象
myCommand.Fill ( myDataSet , "[Sheet1$]" ) ;
//关闭此数据链接
myConn.Close ( ) ;
}
private void InitializeComponent ( )
{
DataGrid1 = new DataGrid ( ) ;
button1 = new Button ( ) ;
SuspendLayout ( ) ;
DataGrid1.Name = "DataGrid1";
DataGrid1.Size = new System.Drawing.Size ( 400 , 200 ) ;
button1.Location = new System.Drawing.Point ( 124 , 240 ) ;
button1.Name = "button1" ;
button1.TabIndex = 1 ;
button1.Text = "读取数据" ;
button1.Size = new System.Drawing.Size (84 , 24 ) ;
button1.Click += new System.EventHandler ( this.button1_Click ) ;
this.AutoScaleBaseSize = new System.Drawing.Size ( 6 , 14 ) ;
this.ClientSize = new System.Drawing.Size ( 400 , 280 ) ;
this.Controls.Add ( button1 ) ;
this.Controls.Add ( DataGrid1 ) ;
this.Name = "Form1" ;
this.Text = "读取Excle表格中的数据,并用DataGrid显示出来!" ;
this.ResumeLayout ( false ) ;
}
private void button1_Click ( object sender , System.EventArgs e )
{
DataGrid1.DataMember= "[Sheet1$]" ;
DataGrid1.DataSource = myDataSet ;
}
static void Main ( )
{
Application.Run ( new Form1 ( ) ) ;
}
}