开发者

C# Excel Read Problem

开发者 https://www.devze.com 2023-01-10 07:03 出处:网络
my excel N开发者_如何学JAVAame|Telephone| |Color|Car| |John|Jon| i need \"|John|Jon|\" how to select OleDbCommand? third row start

my excel

|N开发者_如何学JAVAame|Telephone|
|Color|Car|
|John|Jon|

i need "|John|Jon|" how to select OleDbCommand? third row start

My Csharp Not Work Code:

ExcelCommand.CommandText = @"SELECT * FROM " + SpreadSheetName + " Where RowNumber > 3";

Thank you...


This worked for me. You can change the SELECT statement as you wish (specific rows, multiple columns, ...) to get a single result or a set of rows returned.

string connectionString = @"Provider=Microsoft.Jet.OleDb.4.0;Data Source=test.xls;";
connectionString += "Extended Properties=Excel 8.0;";
OleDbConnection con = new OleDbConnection(connectionString);

DataSet ds = new DataSet("stuff");

OleDbDataAdapter adapter = new OleDbDataAdapter();
// adapter.SelectCommand = new OleDbCommand("Select * from [Sheet1$A1:A100];", con);
// adapter.SelectCommand = new OleDbCommand("Select * from [Sheet1$];", con);
adapter.SelectCommand = new OleDbCommand("Select * from [Sheet1$] where [A] = 'John';", con);
adapter.Fill(ds);

foreach (DataRow dr in ds.Tables[0].Rows)
{
    foreach (DataColumn dc in ds.Tables[0].Columns)
    {
        Console.WriteLine(dr[dc].ToString());
    }
}


May be instead "RowNumber > 3" use "RowNumber = 3". "|John|Jon|" - third row.

0

精彩评论

暂无评论...
验证码 换一张
取 消