Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Converting some vb types to C#/.Net

Posted on 2016-08-03
3
Medium Priority
?
102 Views
Last Modified: 2016-08-10
I'm converting a vb class to C#/.Net. I can't find equivalents for the following:
RecordSet
FieldAttributeEnum
DataTypeEnum

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
                    FieldAttributeEnum.adFldUpdatable
        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

0
Comment
Question by:allelopath
3 Comments
 
LVL 20

Expert Comment

by:Daniel Van Der Werken
ID: 41740804
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();

            try
            {
                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

0
 
LVL 1

Author Comment

by:allelopath
ID: 41740839
My apologies on not being clear in my question. The goal is to move away from ADODB.
0
 
LVL 35

Accepted Solution

by:
YZlat earned 2000 total points
ID: 41740896
Recordet would be quivalent of DataSet/Datatable


I'd suggest something like this:


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

    Array.ForEach(
    dgv.Columns.Cast<DataGridViewColumn>().ToArray(), 
    arg => dt.Columns.Add(arg.HeaderText, arg.ValueType));
    Array.ForEach(
    dgv.Rows.Cast<DataGridViewRow>().ToArray(), 
    arg => dt.Rows.Add(arg.Cells.Cast<DataGridViewCell>().Select(cell => cell.Value)));

    return dt;
}

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question