Question

Currently, I just create an OLEDB connection, run a query on it and load the result set into a SSIS object. I don't know what this Object really is. After that, I load this Object into a DataTable in my C# code. Instead of doing all this, is there a way to directly load this result set into a data table ? Also, is there a way to get the number of rows in the result set from the object itself ? Right now, I load it into a data table and then get the number of rows as myDataTable.Rows.Count;

Thanks.

Était-ce utile?

La solution

The solution would be to use an ADO.NET connection instead of OLEDB. If you use ADO.NET connection, you will get ADO.NET DataSet object. A DataSet is a collection of DataTable.

Some links for DataSet tutorials -

http://www.dotnetperls.com/dataset

Scott Mitchell's tut -

http://msdn.microsoft.com/en-us/library/aa581776.aspx

Also, if you want to get the number of rows in your OLEDB resultset (actually an ADODB recordset) using C# , then use this -

using ADODB;

  ADODB.Recordset resultSet = (ADODB.Recordset)Dts.Variables["MyResultSet"].Value;
  int rows = resultSet.RecordCount;

Don't for get to add a reference to ADODB as follows – Solution Explorer > References > COM tab > Microsoft ActiveX Data Objects 2.X Library > OK. File menu > Save All

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top