Solved

Convert C# to vb.net urgent?

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now