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

前端 未结 6 775
一个人的身影
一个人的身影 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 03:40

    I think you need to append the .ToString() method when you perform the .Fill().

    Something like this:

    OleDbDataAdapter oleDA = new OleDbDataAdapter();
    DataTable dt = new DataTable();
    oleDA.Fill(dt, Dts.Variables["My_Result_Set"].Value.ToString()); 
    

    From the documentation here:

    Fill(DataTable, Object) Adds or refreshes rows in a DataTable to match those in an ADO Recordset or Record object using the specified DataTable and ADO objects.

    It looks like in your implementation, you are trying to pass an unexpected type to the .Fill() method.

    0 讨论(0)
  • 2021-01-03 03:54

    In my case the problem was resolved changing the code and using DataSet for Fill instead DataTable

    OleDbDataAdapter oleDA = new OleDbDataAdapter();
    DataSet ds = new DataSet();
    oleDA.Fill(ds, "MyTableName"); 
    DataTable dt = ds.Tables["MyTableName"];
    
    0 讨论(0)
  • 2021-01-03 03:56

    Below worked for me without Fill.

    OleDbDataAdapter oleDA = new OleDbDataAdapter();
    DataSet ds = new DataSet();
    ds = (DataSet)Dts.Variables["User::myresultSet"].Value;
    
    0 讨论(0)
  • 2021-01-03 03:57

    This error happens when you have not connected two components in SSIS. See image - The execute SQL task produces an ADO record set which will be consumed by the C# script. That ADO is stored in an SSIS object variable (not shown in image) and is picked up by the C# script which I mentioned in my question.

    enter image description here

    0 讨论(0)
  • 2021-01-03 04:01

    I had the same or very similar error and the problem was in the Execute SQL Task that loaded the Object variable that I was passing in, I had the ResultSet set to Single row and it needed to be Full result set.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题