在DataSet中填充数据时找不到可安装的ISAM [英] Could not find installable ISAM while filling data in DataSet

查看:197
本文介绍了在DataSet中填充数据时找不到可安装的ISAM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题是重复的,但我的问题是我已经尝试了几乎所有的解决方案的链接,我没有获得成功。所以这里是场景:
我有一个输入类型=文件&当我点击提交按钮时,它会POST文件。



这里是代码:

  [HttpPost] 
public ActionResult索引(HttpPostedFileBase excel_File)
{
if(excel_File!= null)
{
//保存上传文件到光盘。
string saved_FileName = Path.Combine(@ ConfigurationManager.AppSettings [excel_file_storage_path] + excel_File.FileName); //从web.config获取文件上传位置
excel_File.SaveAs(saved_FileName);
var connectionString = string.Format(Provider = Microsoft.ACE.OLEDB.12.0; Data Source = {0};扩展属性= Excel 12.0 Xml; HDR = YES,saved_FileName);
//从Sheet1工作表中填写数据集中的信息。
var adapter = new OleDbDataAdapter(SELECT * FROM [Sheet1 $],connectionString);
var ds = new DataSet();
adapter.Fill(ds); //我在这里收到错误
DataTable data = ds.Tables [0];
var obj_Table = new DataTable(Sample_Upload_Expense);
obj_Table.Columns.Add(Id,typeof(Int16));
obj_Table.Columns.Add(Name,typeof(string)); $ int $($ i $)
(Id),data.Rows [i] .Field< string>(Name));
}
var arrParam = new List< SqlParameter>();
var para = new SqlParameter();
para.ParameterName =@RowList;
para.SqlDbType = System.Data.SqlDbType.Structured;
para.Value = obj_Table;
var pNumRowsChanged = new SqlParameter(@ NumRowsChanged,SqlDbType.Int);
pNumRowsChanged.Value = 0;
arrParam.Add(para);
arrParam.Add(pNumRowsChanged);
string proc =SPInsertExpense;
int no = DataProvider.ProcRetunAffectedRows(proc,arrParam);
return View();
}

帮助我。我被困了2天,我无法找到解决方案。



web.config中的文件路径:

 <&的appSettings GT; 
< add key =excel_file_storage_pathvalue =D:\webapps\uploads\UploadedExcelDocuments\/>
< / appSettings>

我尝试过:


  1. 我安装了2007 Office System驱动程序 - 数据连接组件,以解决是否存在任何连接问题,但无法正常工作。

  2. 尝试单引号围绕数据源。

  3. 我将静态路径放在连接字符串中,但也不起作用。

  4. 另外这个,虽然它与我的问题无关。


解决方案

终于有效了。我试过这个,&有效。在连接字符串中的实际,最后需要两个; (分号)。所以我的 connectionString 必须如下所示:

  var connectionString = string.Format(Provider = Microsoft .ACE.OLEDB.12.0; Data Source = {0};扩展属性='Excel 12.0 Xml; HDR = YES;';,saved_FileName); 


I know this question is repeated but problem with me is I have tried almost all the link for solution and I didnt get the success. So here is the scenario: I have a input type = file & when I click on submit button, it POST the file.

here is the code:

[HttpPost]
public ActionResult Index(HttpPostedFileBase excel_File)
{
  if (excel_File != null)
  {
    //Save the uploaded file to the disc.
    string saved_FileName = Path.Combine(@ConfigurationManager.AppSettings["excel_file_storage_path"] + excel_File.FileName); // Taking file upload location from web.config
    excel_File.SaveAs(saved_FileName);
    var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0 Xml;HDR=YES", saved_FileName);
    //Fill the dataset with information from the Sheet1 worksheet.
    var adapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString);
    var ds = new DataSet();
    adapter.Fill(ds);  // I get error here.
    DataTable data = ds.Tables[0];
    var obj_Table = new DataTable("Sample_Upload_Expense");
    obj_Table.Columns.Add("Id", typeof(Int16));
    obj_Table.Columns.Add("Name", typeof(string));
    for (int i = 0; i < data.Rows.Count - 1; i++)
    {
      obj_Table.Rows.Add(data.Rows[i].Field<double>("Id"), data.Rows[i].Field<string>("Name"));
    }
    var arrParam = new List<SqlParameter>();
    var para = new SqlParameter();
    para.ParameterName = "@RowList";
    para.SqlDbType = System.Data.SqlDbType.Structured;
    para.Value = obj_Table;
    var pNumRowsChanged = new SqlParameter("@NumRowsChanged", SqlDbType.Int);
    pNumRowsChanged.Value = 0;
    arrParam.Add(para);
    arrParam.Add(pNumRowsChanged);
    string proc = "SPInsertExpense";
    int no = DataProvider.ProcRetunAffectedRows(proc, arrParam);
    return View();
}

Help me. I am stuck from 2 days and I am not able to find the solution.

file path in web.config:

<appSettings>
<add key="excel_file_storage_path" value="D:\webapps\uploads\UploadedExcelDocuments\" />
</appSettings>

I have tried:

  1. I installed 2007 Office System Driver - Data Connectivity Components to solve if there is any connectivity issue but it doesnt work.
  2. Tried putting single quotes around the data source.
  3. I put static path in connection string but that also dont work.
  4. Also this, though it is not related with my issue.

解决方案

Finally it worked. I tried this, & it worked. Actuality in connection string, it needs two ; (semicolons) at the end. So my connectionString must be like follow:

var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0 Xml;HDR=YES;';", saved_FileName);

这篇关于在DataSet中填充数据时找不到可安装的ISAM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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