Solved

Convert C# to vb.net urgent?

Posted on 2007-03-29
2
206 Views
Last Modified: 2010-04-16
try
    {
        DataTable dt = new DataTable();
        objDB = new DatabaseToExcel.DB(ConnectionString);
        dt = objDB.runQuery(query);
        ctl_progress.Visible = true;
        ctl_progress.Minimum = 1;
        ctl_progress.Maximum = dt.Rows.Count + 1;
        ctl_progress.Value = 1;
        //This is to access the first work sheet of your application
        sheet = (Excel.Worksheet)book.Worksheets[1];
        sheet.Name = "SampleExcel";
        for(int i = 1 ; i <= dt.Rows.Count ; i++)
        {
            for(int j = 1 ; j <= dt.Columns.Count ; j++ )
            {
                // This is to add the Data which retrieved from
                // the database into your Excel Sheet.
                ((Excel.Range)sheet.Cells[i,j]).Value2
                                   = dt.Rows[i-1].ItemArray[j-1].ToString();
                //dt.Rows[i-1].ItemArray[j-1].ToString()--> This will retrieve
                // data from your datatable's
                //(i-1)th rows (j-1)st column
            }
            ctl_progress.Value += 1;
        }
        MessageBox.Show("Your Process Completed Successfully");
        ctl_progress.Visible = false;
    }
    catch(Exception e1)
    {
        MessageBox.Show(e1.Message);
    }
0
Comment
Question by:mathieu_cupryk
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18821555
Should be...

    Try
        Dim dt As New DataTable()
        objDB = New DatabaseToExcel.DB(ConnectionString)
        dt = objDB.runQuery(query)
        ctl_progress.Visible = True
        ctl_progress.Minimum = 1
        ctl_progress.Maximum = dt.Rows.Count + 1
        ctl_progress.Value = 1
        ' This is to access the first work sheet of your application
        sheet = CType(book.Worksheets(1), Excel.Worksheet)
        sheet.Name = "SampleExcel"
        For i As Integer = 1 to dt.Rows.Count
            For j As Integer = 1 to dt.Columns.Count
                ' This is to add the Data which retrieved from
                ' the database into your Excel Sheet.
                CType(sheet.Cells(i,j), Excel.Range).Value2
                                   = dt.Rows(i-1).ItemArray(j-1).ToString()
                'dt.Rows[i-1].ItemArray[j-1].ToString()--> This will retrieve
                ' data from your datatable's
                '(i-1)th rows (j-1)st column
            Next
            ctl_progress.Value = ctl_progress.Value + 1
        Next
        MessageBox.Show("Your Process Completed Successfully")
        ctl_progress.Visible = False
    Catch e1 As Exception
        MessageBox.Show(e1.Message)
    End Try
0
 
LVL 2

Expert Comment

by:empoalp
ID: 18822533
You have an automatic C# to vb.net converter in this link.
http://www.kamalpatel.net/ConvertCSharp2VB.aspx
0

Featured Post

Independent Software Vendors: 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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

763 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