【发布时间】:2017-02-14 12:17:34
【问题描述】:
当我想在 C# 应用程序中导入工作表 excel 时出现错误,
ERROR 是“没有为一个或多个必需参数指定值”。
我将 c# 与 MS excel 一起使用。这是我的代码
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.FileName = "";
openFileDialog1.Filter = "Excel File Sheet |*.xls; *.xlsx";
try
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string path = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + openFileDialog1.FileName + ";Extended Properties=\"Excel 8.0;HDR=Yes;\";";
OleDbConnection conn = new OleDbConnection(path);
OleDbDataAdapter da = new OleDbDataAdapter("SELECT Date, PF, [Agent Name], TL, Supervisor, [Sum Under], [Sum Over], [Out of Adherence], Sch, Sum([Out of Adherence %]*100), Sum((100-(100*[Out of Adherence %]))) AS [Adherence % Daily] FROM [Sheet1$] GROUP BY Date, PF, [Agent Name], TL, Supervisor, [Sum Under], [Sum Over], [Out of Adherence], Sch, [Out of Adherence %]", conn);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}
else
return;
}
catch(FieldAccessException ex)
{
MessageBox.Show("ERROR" + ex);
}
请帮我解决这个错误,
谢谢大家..
【问题讨论】:
-
什么样的错误?编译时还是运行时?它出现在哪里?在此处检查一下 - stackoverflow.com/questions/2378763/…,然后检查您的代码中的
Null值。