我有一个错误!请帮我! Microsoft Access数据库引擎找不到对象"asasas".确保该对象存在,并且正确拼写了它的名称和路径名. [英] I have an error! Please help me! The Microsoft Access database engine could not find the object 'asasas'. Make sure the object exists and that you spell its name and the path name correctly.

查看:324
本文介绍了我有一个错误!请帮我! Microsoft Access数据库引擎找不到对象"asasas".确保该对象存在,并且正确拼写了它的名称和路径名.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将.csv文件中的数据导出到C#中的dataGridView.

在此行之后:oda.SelectCommand.ExecuteNonQuery();
我有一个错误:
Microsoft Access数据库引擎找不到对象"asasas".确保对象存在,并且正确拼写其名称和路径名称.


我该如何解决?



有我的代码:


I want to export my data in .csv file to dataGridView in C#.

After this line: oda.SelectCommand.ExecuteNonQuery();
I have an error:
The Microsoft Access database engine could not find the object ''asasas''. Make sure the object exists and that you spell its name and the path name correctly.


How can i fix that?



There is my code:


public DataSet readCSV(string file)
{
if (!File.Exists(file))
return null;
string pathOnly = Path.GetDirectoryName(file);
DataSet ds = new DataSet();
OleDbConnection conn = null;
//string fileConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + pathOnly + "\\;Extended Properties=\"Text;HDR=Yes;FORMAT=Delimited\"";
 
string fileConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ pathOnly +";Extended Properties=Excel 8.0";
OleDbConnection ocn = new OleDbConnection(fileConnStr);
try
{
try
{
conn = new OleDbConnection();
conn.ConnectionString = fileConnStr;
conn.Open();
}
catch
{
MessageBox.Show("Veritabanı bağlantı kuramadı.");
return null;
}
string sql = String.Format("SELECT * FROM {0}", Path.GetFileName(file));
OleDbDataAdapter oda = new OleDbDataAdapter(sql, conn);
oda.SelectCommand.ExecuteNonQuery();
oda.Fill(ds, "TableName");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return null;
}
finally
{
if (conn != null)
conn.Dispose();
}
return ds;
}}}













 private void btnExcelReader_Click(object sender, EventArgs e)
        {
            string dosya;
            //string cevap;
            openFileDialog1.ShowDialog();
            dosya = openFileDialog1.FileName.ToString();

            ClsExcelReader er = new ClsExcelReader();
            DataSet ds = er.readCSV(dosya);

            dataGridViewScanner.DataSource = ds;
}

推荐答案

我想,此链接应该可以为您提供帮助.

http://www.gridview.net/read-excel-file-in-c/ [ ^ ]
I guess, this link should help you out.

http://www.gridview.net/read-excel-file-in-c/[^]


我解决了我的问题.
问题出在我的文件名上.
我的文件名中包含很多.".角色.

选择文件时,更改文件名.
fileName.Replace(.","_")
I solved my problem.
The problem is about my file name.
My file name include a lot of "." character.

When i choose the file, i change the file name.
fileName.Replace(".", "_")


这篇关于我有一个错误!请帮我! Microsoft Access数据库引擎找不到对象"asasas".确保该对象存在,并且正确拼写了它的名称和路径名.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆