Solved

Convert C# to vb.net urgent?

Posted on 2007-03-29
2
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
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…
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…

751 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