首页  编辑  

Excel文件查询

Tags: /C#/数据库和SQL语句/   Date Created:

using System . Data . OleDb;

OleDbConnection vOleDbConnection = new OleDbConnection ();

vOleDbConnection . ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;" +

    @"Data Source=c:\temp\temp.xls;Extended Properties=Excel 8.0;" ;

vOleDbConnection . Open();

OleDbCommand vOleDbCommand = new OleDbCommand (

    "select * from [Sheet1$A1:A10]" , vOleDbConnection);

OleDbDataReader vOleDbDataReader = vOleDbCommand . ExecuteReader();

while (vOleDbDataReader . Read())

   textBox1 . AppendText(vOleDbDataReader . GetValue( 0 ) . ToString() + "\r\n" );