Solved

Convert C# to vb.net urgent?

Posted on 2007-03-29
2
203 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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