private void btnLKMSearch_Click(object sender, EventArgs e)
{
if (openFileDialogLKM.ShowDialog() ==DialogResult.OK)
{
txtLKMSS.Text = openFileDialogLKM.FileName;
}
//MessageBox.Show(Directory.GetParent(txtLKMSS.Text).ToString());
ExcelConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Directory.GetParent(txtLKMSS.Text) + ";Extended Properties='Text;FMT=Delimited;HDR=YES;'");
ExcelConnection.Open();
Share.ExcelApp = new Excel.Application();
Excel.Worksheet sheet = Share.ExcelApp.Application.Workbooks.Open(txtLKMSS.Text).Sheets[1];
string sheetName = sheet.Name;
string strSQL = "Select * from " + "[" + sheetName + "]";
//+ "where CCN=" + cboxCNN.Text;
ExcelDa = new OleDbDataAdapter(strSQL, ExcelConnection);
dataSet = new DataSet();
ExcelDa.Fill(dataSet, "LKMSS");
}
错误提示:System.Data.OleDb.OleDbException:“Microsoft Access 数据库引擎找不到对象“DAILY_STOCK_STATUS9-5-2018.txt”。请确保该对象存在,并正确拼写其名称和路径名。如果“DAILY_STOCK_STATUS9-5-2018.txt”不是本地对象,请检查网络连接或与服务器管理员联系。”我是用openfiledialog访问的CSVfile,但是错误提示里面却说要找Txt文件,不明白错在哪里,希望大神帮忙看看~~
{
if (openFileDialogLKM.ShowDialog() ==DialogResult.OK)
{
txtLKMSS.Text = openFileDialogLKM.FileName;
}
//MessageBox.Show(Directory.GetParent(txtLKMSS.Text).ToString());
ExcelConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Directory.GetParent(txtLKMSS.Text) + ";Extended Properties='Text;FMT=Delimited;HDR=YES;'");
ExcelConnection.Open();
Share.ExcelApp = new Excel.Application();
Excel.Worksheet sheet = Share.ExcelApp.Application.Workbooks.Open(txtLKMSS.Text).Sheets[1];
string sheetName = sheet.Name;
string strSQL = "Select * from " + "[" + sheetName + "]";
//+ "where CCN=" + cboxCNN.Text;
ExcelDa = new OleDbDataAdapter(strSQL, ExcelConnection);
dataSet = new DataSet();
ExcelDa.Fill(dataSet, "LKMSS");
}
错误提示:System.Data.OleDb.OleDbException:“Microsoft Access 数据库引擎找不到对象“DAILY_STOCK_STATUS9-5-2018.txt”。请确保该对象存在,并正确拼写其名称和路径名。如果“DAILY_STOCK_STATUS9-5-2018.txt”不是本地对象,请检查网络连接或与服务器管理员联系。”我是用openfiledialog访问的CSVfile,但是错误提示里面却说要找Txt文件,不明白错在哪里,希望大神帮忙看看~~
{
if (openFileDialogLKM.ShowDialog() ==DialogResult.OK)
{
txtLKMSS.Text = openFileDialogLKM.FileName;
}
//MessageBox.Show(Directory.GetParent(txtLKMSS.Text).ToString());
ExcelConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Directory.GetParent(txtLKMSS.Text) + ";Extended Properties='Text;FMT=Delimited;HDR=YES;'");
ExcelConnection.Open();
Share.ExcelApp = new Excel.Application();
Excel.Worksheet sheet = Share.ExcelApp.Application.Workbooks.Open(txtLKMSS.Text).Sheets[1];
string sheetName = sheet.Name;
string strSQL = "Select * from " + "[" + sheetName + "]";
//+ "where CCN=" + cboxCNN.Text;
ExcelDa = new OleDbDataAdapter(strSQL, ExcelConnection);
dataSet = new DataSet();
ExcelDa.Fill(dataSet, "LKMSS");
}
应该是标红处的错,改成Path.GetFullPath(txtLKMSS.Text)
Directory.GetParent(txtLKMSS.Text)这个是文本文件对应的目录你到底要读取什么