C# 如何修复';System.Data.OleDb.OleDbException';?
首先,很抱歉问一下如何修复这个错误(我知道这是一个常见的问题),但我对C#还很陌生,似乎找不到解决方法 我正在制作一个从excel文件导入数据并在DataGridView中显示的windows窗体。执行时,我得到一个错误: “类型为'System.Data.OleDb.OLEDBEException'的未处理异常” 在System.Data.dll中发生其他信息:未为指定值 一个或多个必需参数。” 这是我的密码:C# 如何修复';System.Data.OleDb.OleDbException';?,c#,datagridview,C#,Datagridview,首先,很抱歉问一下如何修复这个错误(我知道这是一个常见的问题),但我对C#还很陌生,似乎找不到解决方法 我正在制作一个从excel文件导入数据并在DataGridView中显示的windows窗体。执行时,我得到一个错误: “类型为'System.Data.OleDb.OLEDBEException'的未处理异常” 在System.Data.dll中发生其他信息:未为指定值 一个或多个必需参数。” 这是我的密码: using System; using System.Collections.Ge
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
namespace WindowsFormsApplication2
{
public partial class CurrentOrders : Form
{
public CurrentOrders()
{
InitializeComponent();
}
private void CurrentOrders_Load(object sender, EventArgs e)
{
}
private void BackBtn_Click(object sender, EventArgs e)
{
NewOrder NewOrd = new NewOrder();
this.Hide();
NewOrd.Show();
}
private void DataGridViewLOG_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Tombies\Documents\Visual Studio 2013\Projects\WindowsFormsApplication2\WindowsFormsApplication2\PCSsheet.xls" + @";Extended Properties=""Excel 12.0;HDR=Yes;IMEX=1;ImportMixedTypes=Text;TypeGuessRows=0""";
OleDbCommand command = new OleDbCommand
(
"SELECT DATE, CUSTOMER, PO, COMMENTS, PCS FROM [LOG$]", conn
);
DataSet DsOrderLOG = new DataSet();
OleDbDataAdapter Adapter = new OleDbDataAdapter(command);
conn.Open();
Adapter.Fill(DsOrderLOG);
conn.Close();
DataGridViewLOG.DataSource = DsOrderLOG.Tables[0];
}
}
}
我知道这和底部的“适配器。填充”有关,但从那以后我就迷路了
感谢您的帮助
Date
可能是罪魁祸首。试着把它(一个所有其他列名)放在括号中:
"SELECT [DATE], [CUSTOMER], [PO], [COMMENTS], [PCS] FROM [LOG$]", conn
感谢您的建议,但是它仍然会给出相同的错误:System.Data.OleDb.OledBeException类型的未处理异常发生在System.Data.dll中。其他信息:没有为一个或多个必需的参数提供值。您确信Excel文件中的列名是正确的吗?是的,我只是仔细检查了所有列名。