System.ArgumentException: Object is not an ADODB.RecordSet or an ADODB.Record

前端 未结 6 819
一个人的身影
一个人的身影 2021-01-03 03:10

I used the code below to fill a data table -

OleDbDataAdapter oleDA = new OleDbDataAdapter();
DataTable dt = new DataTable();
oleDA.Fill(dt, Dts.Variables[         


        
6条回答
  •  梦谈多话
    2021-01-03 04:04

    In a script task, I created a datatable called DtUsers, created columns in the datatable, added rows and assigned values to the row cells. I then stored this datatable in an object variable called activeDirectoryUsers:

    Dts.Variables["User::activeDirectoryUsers"].Value = DtUsers;
    

    I then created a Data Flow and added a Source Script Component. I tried to use Fill() and received the same error as the OP.

    OleDbDataAdapter da = new OleDbDataAdapter();
    DataTable dt = new DataTable();
    da.Fill(dt, Variables.activeDirectoryUsers);  //error here
    

    Object is not an ADODB.RecordSet or an ADODB.Record

    The solution for me was twofold:

    1. Add the DtUsers datatable to a DataSet and then store the DataSet in the object variable.

      DataSet ds = new DataSet();
      ds.Tables.Add(DtUsers);
      Dts.Variables["User::activeDirectoryUsers"].Value = ds;
      
    2. In the Source Script Component, create a new DataSet and cast the object variable to type DataSet, and assign it to the DataSet:

      DataSet ds = (DataSet)Variables.activeDirectoryUsers;
      if (ds == null || ds.Tables.Count == 0) return;
      DataTable dt = ds.Tables[0];
      //do stuff with dt...
      

    This article led me to this solution.

提交回复
热议问题