Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C Excel读取问题_C#_Excel - Fatal编程技术网

C# C Excel读取问题

C# C Excel读取问题,c#,excel,C#,Excel,我的excel |Name|Telephone| |Color|Car| |John|Jon| 我需要| John | Jon |如何选择OLEDB命令?第三排发车 我的Csharp不工作代码: ExcelCommand.CommandText = @"SELECT * FROM " + SpreadSheetName + " Where RowNumber > 3"; 谢谢…可能是RowNumber>3使用RowNumber=3|John | Jon |-第三行。可以改为RowNum

我的excel

|Name|Telephone|
|Color|Car|
|John|Jon|
我需要| John | Jon |如何选择OLEDB命令?第三排发车

我的Csharp不工作代码:

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

谢谢…

可能是RowNumber>3使用RowNumber=3|John | Jon |-第三行。

可以改为RowNumber>3使用RowNumber=3|约翰·乔恩——第三排。

这对我来说很有效。您可以根据需要更改SELECT语句,包括特定的行、多列等。。。获取返回的单个结果或一组行

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());
    }
}

这对我有用。您可以根据需要更改SELECT语句,包括特定的行、多列等。。。获取返回的单个结果或一组行

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());
    }
}

无法工作,请帮助我ExcelCommand.CommandText=@SELECT*FROM+SpreadSheetName+其中RowNumber=3;错误:一个或多个必需参数没有给定值。可能需要尝试以下语法:SELECT*FROM[+SpreadSheetName+$A3:B3]其中$A3:B3-单元格范围不工作请帮助我ExcelCommand.CommandText=@SELECT*FROM+SpreadSheetName+其中RowNumber=3;错误:没有为一个或多个必需参数提供值。可以尝试以下语法:从[+SpreadSheetName+$A3:B3]中选择*,其中$A3:B3-单元格范围