C# 不能在每个语句中使用Excel标题名称
我使用OleDbDataReader从Excel工作表中读取值 当我将结果收集到变量中时,有时我可以使用Excel列标题,有时我不能 当它是一个日期字段时,我需要引用列号C# 不能在每个语句中使用Excel标题名称,c#,excel,oledbdatareader,C#,Excel,Oledbdatareader,我使用OleDbDataReader从Excel工作表中读取值 当我将结果收集到变量中时,有时我可以使用Excel列标题,有时我不能 当它是一个日期字段时,我需要引用列号 string description = (string)reader["Description"]; var bsd = reader.GetDateTime(2); var bfd = reader.GetDateTime(3); string wc = (string)reader["Main WorkCtr"]; 如
string description = (string)reader["Description"];
var bsd = reader.GetDateTime(2);
var bfd = reader.GetDateTime(3);
string wc = (string)reader["Main WorkCtr"];
如何为日期变量使用列标题
如果我将代码更改为reader[Bas.start date],运行时会出现如下错误:
它没有拼错。你说不能是什么意思?你得到一个错误异常?关于哪个代码?主WorkCtr和Description列的类型是什么?同时展示你的作品。我的问题是我不知道在使用reader.GetDateTime2时如何键入它;当我键入reader.GetDateTimeBas时。开始日期;我在编译器中收到此错误消息:错误1“System.Data.Common.DbDataReader.GetDateTimeint”的最佳重载方法匹配有一些无效的参数哪些是您的所有列的类型?它在编译之前失败,因为reader.GetDateTimeBas。开始日期不是正确的输入方式。在上面的注释中命名错误。@Skram,因为所有GetXXX方法都将int参数作为从零开始的列号。