• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 108
  • Last Modified:

Converting some vb types to C#/.Net

I'm converting a vb class to C#/.Net. I can't find equivalents for the following:

I think RecordSet can be replaced with DataSet, but I don't know about the other two. Any ideas?

Some example code:

    Private Function CreateRecordsetFromDataGrid(ByVal DGV As DataGridView) As Recordset
        Dim rs As New Recordset
        'Create columns in ADODB.Recordset
        Dim FieldAttr As FieldAttributeEnum
        FieldAttr = FieldAttributeEnum.adFldIsNullable Or FieldAttributeEnum.adFldIsNullable Or
        For Each iColumn As DataGridViewColumn In DGV.Columns
            'only add Visible columns
            If iColumn.Visible = True Then
                Dim FieldType As DataTypeEnum
                'select dataType
                If iColumn.ValueType Is GetType(Boolean) Then
                    FieldType = DataTypeEnum.adBoolean

Open in new window

1 Solution
Daniel Van Der WerkenIndependent ConsultantCommented:
You need to add the COM reference of Microsoft ActiveX Data Objects 2.X Library.

Create ADO Connection and Recordset Objects in Visual C# .NET

Create a new Visual C# .NET Windows application project.
On the Project menu, click Add Reference.
Click the COM tab. Click Microsoft ActiveX Data Objects 2.X Library.

        // You must first load the COM reference Microsoft ActiveX Data Objects 2.X Library

        private ADODB.Recordset CreateRecordsetFromDataGrid(DataGridView DGV)
            ADODB.Recordset rs = new ADODB.Recordset();

                ADODB.FieldAttributeEnum FieldAttr = ADODB.FieldAttributeEnum.adFldIsNullable | ADODB.FieldAttributeEnum.adFldUpdatable;

                foreach (DataGridViewColumn iColumn in DGV.Columns)
                    if (iColumn.Visible)
                        ADODB.DataTypeEnum FieldType;

                        if (iColumn.ValueType == typeof(Boolean))
                            FieldType = ADODB.DataTypeEnum.adBoolean;
            catch (Exception ex)
                // Don't leave this blank!

            return rs;

Open in new window

allelopathAuthor Commented:
My apologies on not being clear in my question. The goal is to move away from ADODB.
Recordet would be quivalent of DataSet/Datatable

I'd suggest something like this:

private DataTable CreateRecordsetFromDataGrid(DataGridView dgv)
    Datatable dt = new DataTable();

    arg => dt.Columns.Add(arg.HeaderText, arg.ValueType));
    arg => dt.Rows.Add(arg.Cells.Cast<DataGridViewCell>().Select(cell => cell.Value)));

    return dt;

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now