IErrorInfo.GetDescription失败,E_FAIL(0X80004005).System.Data而数据适配器填充() [英] IErrorInfo.GetDescription failed with E_FAIL(0x80004005).System.Data while data adapter Fill()

查看:417
本文介绍了IErrorInfo.GetDescription失败,E_FAIL(0X80004005).System.Data而数据适配器填充()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从CSV文件中获取数据,通过填写()方法,我得到一个异常IDK的为什么它出现时,请查看code和建议看好answer.note,如果参数S不有任何空间,意味着它工作正常。如果有空间,意味着如何克服,不建议临时重命名和所有的。

  ///<总结>
///导入功能对于CSV Delimeted文件
///< /总结>
///< PARAM NAME =S>文件名< /参数>
私人数据表Import4csv(字符串s)
{
    字符串文件= Path.GetFileName(S);
    字符串DIR = Path.GetDirectoryName(S);
    字符串sConnection =供应商= Microsoft.Jet.OLEDB.4.0;
                             +数据源= \+方向+\\\;
                             +扩展属性= \文本; HDR = YES; FMT =分隔\;
    尝试
    {
        VAR objConn =新的OleDbConnection(sConnection);
        objConn.Open();
        变种DS =新的DataSet();
        VAR DA =新OleDbDataAdapter的(SELECT * FROM+文件,sConnection);
        da.Fill(DS); //在这一行越来越例外。
        objConn.Close();
        返回ds.Tables [0];
    }
    赶上(例外前)
    {
        Trace.WriteLine(ex.Message + ex.Source);
        返回null;
    }
}
 

解决方案

  VAR DA =新OleDbDataAdapter的(SELECT * FROM`+文件+`,sConnection);
 

附近的波浪键..

I'm trying to get data from CSV file , by using fill() method i got a exception idk why it arise,please review code and suggest optimistic answer.note that if parameter "s" doesn't have any space means it works fine. if it have space means how to overcome that,don't suggest temporary rename and all.

/// <summary>
/// Import Function For CSV Delimeted File
/// </summary>
/// <param name="s">File Name</param>
private DataTable Import4csv(string s)
{
    string file = Path.GetFileName(s);
    string dir = Path.GetDirectoryName(s);
    string sConnection = "Provider=Microsoft.Jet.OLEDB.4.0;"
                             + "Data Source=\"" + dir + "\\\";"
                             + "Extended Properties=\"text;HDR=YES;FMT=Delimited\"";
    try
    {
        var objConn = new OleDbConnection(sConnection);
        objConn.Open();
        var ds = new DataSet();
        var da = new OleDbDataAdapter("SELECT * FROM " + file, sConnection);
        da.Fill(ds);        // getting exception on this line.
        objConn.Close();
        return ds.Tables[0];
    }
    catch (Exception ex)
    {
        Trace.WriteLine(ex.Message + ex.Source);
        return null;
    }
}

解决方案

var da = new OleDbDataAdapter("SELECT * FROM `" + file + "`", sConnection);

near the tilde key..

这篇关于IErrorInfo.GetDescription失败,E_FAIL(0X80004005).System.Data而数据适配器填充()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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