Copy data from Recordset to DataTable in .net

Copy data from Recordset to DataTable in .Net

You can copy data from Recordset to DataTable by using the following code..

            ADODB.Connection oConn = new ADODB.Connection();

            oConn.Open("Connection String", "", "", 0);

            string strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(strFileName) + "]";

            ADODB.Recordset rs = new ADODB.Recordset();

            System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter();

            DataTable dt = new DataTable();

            rs.Open(strQuery, " Connection String,                ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 1);

            adapter.Fill(dt, rs);

            return dt;

Ebook Download
View all
Learn
View all