• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

VB.NET Conversion from C# Needed

I need the following code converted to VB.net from C#.  The original code comes from Microsoft:
http://support.microsoft.com/default.aspx?scid=kb;en-us;319264

Here's the code from the site listed above:
// Add namespaces at top.
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

//Crystal Report Variables
CrystalReport1 crReportDocument = new CrystalReport1();

//'CrystalReport1' must be the name the CrystalReport
TableLogOnInfo crTableLogOnInfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();

//Crystal Report Properties
CrystalDecisions.CrystalReports.Engine.Database crDatabase;
CrystalDecisions.CrystalReports.Engine.Tables crTables;
CrystalDecisions.CrystalReports.Engine.Table crTable;

//Then, use following code sample to add the logic in the Page_Load method of your Web Form:

crConnectionInfo.ServerName = "EnterServerNameHere";
crConnectionInfo.DatabaseName = "EnterDatabaseNameHere";
crConnectionInfo.UserID = "EnterUserIDHere";
crConnectionInfo.Password = "EnterPasswordHere";
crDatabase = crReportDocument.Database;
crTables = crDatabase.Tables;

foreach(CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
      crTableLogOnInfo = crTable.LogOnInfo;
      crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
      crTable.ApplyLogOnInfo(crTableLogOnInfo);
}

CrystalReportViewer1.ReportSource = crReportDocument;
                        
0
simplemoney
Asked:
simplemoney
1 Solution
 
mani_saiCommented:
Here is the VB.Net Code:

You need have proper reference in your solution:

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

       'Crystal Report Variables
        Dim crReportDocument As CrystalReport1 = New CrystalReport1

        'CrystalReport1' must be the name the CrystalReport
        Dim crTableLogOnInfo As TableLogOnInfoDim = New TableLogOnInfo
        Dim crConnectionInfo As ConnectionInfo = New ConnectionInfo

        'Crystal Report Properties
        CrystalDecisions.CrystalReports.Engine.Database(crDatabase)
        CrystalDecisions.CrystalReports.Engine.Tables(crTables)
        CrystalDecisions.CrystalReports.Engine.Table(crTable)

        'Then, use following code sample to add the logic in the Page_Load method of your Web Form:

        crConnectionInfo.ServerName = "EnterServerNameHere"
        crConnectionInfo.DatabaseName = "EnterDatabaseNameHere"
        crConnectionInfo.UserID = "EnterUserIDHere"
        crConnectionInfo.Password = "EnterPasswordHere"
        crDatabase = crReportDocument.Database
        crTables = crDatabase.Tables

        For Each crTable In CrystalDecisions.CrystalReports.Engine.Table

            crTableLogOnInfo = crTable.LogOnInfo
            crTableLogOnInfo.ConnectionInfo = crConnectionInfo
            crTable.ApplyLogOnInfo(crTableLogOnInfo)

        Next


        CrystalReportViewer1.ReportSource = crReportDocument

Thanks
0
 
Bob LearnedCommented:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Dim crReportDocument As CrystalReport1 = New CrystalReport1()
Dim crTableLogOnInfo As TableLogOnInfo = New TableLogOnInfo()
Dim crConnectionInfo As ConnectionInfo = New ConnectionInfo()
Dim crDatabase As CrystalDecisions.CrystalReports.Engine.Database
Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table

crConnectionInfo.ServerName = "EnterServerNameHere"
crConnectionInfo.DatabaseName = "EnterDatabaseNameHere"
crConnectionInfo.UserID = "EnterUserIDHere"
crConnectionInfo.Password = "EnterPasswordHere"
crDatabase = crReportDocument.Database
crTables = crDatabase.Tables

For Each crTable As CrystalDecisions.CrystalReports.Engine.Table In crTables

 crTableLogOnInfo = crTable.LogOnInfo
 crTableLogOnInfo.ConnectionInfo = crConnectionInfo
 crTable.ApplyLogOnInfo(crTableLogOnInfo)

Next

CrystalReportViewer1.ReportSource = crReportDocument


Bob
0
 
LacutahCommented:
   'Add to your imports
    Imports CrystalDecisions.CrystalReports.Engine, CrystalDecisions.Shared

    'In the declartions / form wide variables secion, add the following
    Private crReportDocument As New CrystalReport1()
    Private crTableLogOnInfo = New TableLogOnInfo()
    Private crConnectionInfo As New ConnectionInfo()

    Private crDatabase As CrystalDecisions.CrystalReports.Engine.Database
    Private crTables As CrystalDecisions.CrystalReports.Engine.Tables
    Private crTable As CrystalDecisions.CrystalReports.Engine.Table

    'Use the following code in your Page_Load method of your web form
    crConnectionInfo.ServerName = "EnterServerNameHere";
    crConnectionInfo.DatabaseName = "EnterDatabaseNameHere";
    crConnectionInfo.UserID = "EnterUserIDHere";
    crConnectionInfo.Password = "EnterPasswordHere";
    crDatabase = crReportDocument.Database;
    crTables = crDatabase.Tables;

    For Each crTable In crTables
        crTableLogOnInfo = crTable.LogOnInfo;
        crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
        crTable.ApplyLogOnInfo(crTableLogOnInfo);
    Next
    CrystalReportViewer1.ReportSource = crReportDocument;
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
Bob LearnedCommented:
Dog pile :)

Bob
0
 
mani_saiCommented:
Here is my working code, you can take it for your reference if you need it:

 'Build a connection string
       Dim crReportDocument As FunctionalTeamReport    '(this is my crystal report--- .rpt)
        Dim strConnection As String = ConfigurationSettings.AppSettings("ConnectionString")
        Dim objConnection As New SqlConnection(strConnection)

        Dim sqlString As String

       'Here i am building a string that execute a SQL Stored Proc:

        sqlString = "Execute FunctionalTeamReport "
        sqlString = sqlString & "'" & Trim(Request.QueryString("GroupNo")) & "',"
        sqlString = sqlString & "'" & Trim(Request.QueryString("DecisionMakers")) & "',"
        sqlString = sqlString & "'" & Trim(Request.QueryString("RecoveryExperts")) & "',"
        sqlString = sqlString & "'" & Trim(Request.QueryString("OperationalStaff")) & "',"
        sqlString = sqlString & "'" & Trim(Request.QueryString("ExecutiveStaff")) & "',"
        sqlString = sqlString & "'" & Trim(Request.QueryString("EmergencyCertifiedPersonnel")) & "',"
        sqlString = sqlString & "'" & Trim(Request.QueryString("VendorSupport")) & "',"
        sqlString = sqlString & "'" & Trim(Request.QueryString("EPLO")) & "'"

        Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
        Dim myLogin As CrystalDecisions.Shared.TableLogOnInfo
        crReportDocument = New FunctionalTeamReport

        For Each myTable In crReportDocument.Database.Tables
            myLogin = myTable.LogOnInfo
            myLogin.ConnectionInfo.Password = ConfigurationSettings.AppSettings("DevSQLPassword")                      myLogin.ConnectionInfo.UserID = ConfigurationSettings.AppSettings("DevSQLUserID")
            myTable.ApplyLogOnInfo(myLogin)
        Next


        Dim da As SqlDataAdapter
        da = New SqlDataAdapter(sqlString, objConnection)

        Dim ds As New DataSet
        da.Fill(ds, "FunctionalTeamReportDSTable")

        crReportDocument.SetDataSource(ds)


        crvCOGReportsIES.HasPageNavigationButtons = True
        crvCOGReportsIES.HasRefreshButton = False
        crvCOGReportsIES.HasGotoPageButton = False
        crvCOGReportsIES.HasZoomFactorList = False
        crvCOGReportsIES.HasSearchButton = False
        crvCOGReportsIES.DisplayToolbar = False
        crvCOGReportsIES.HasDrillUpButton = False
        crvCOGReportsIES.DisplayToolbar = True


        crvCOGReportsIES.ReportSource = crReportDocument

Thanks
0
 
weddellCommented:
Use this,

http://www.kamalpatel.net/ConvertCSharp2VB.aspx

It's not totally perfect but it is very good
0
 
simplemoneyAuthor Commented:
Each response has some type of error, usually that TableLogOnInfoDim was not defined.  TheLearnedOne came the closest, so far, but I'm getting a VB error on the For loop, specifically on crTable which says "Variable crTable hides a variable in an enclosing block"

Thanks.
0
 
mani_saiCommented:
This is tested working code:
You can try with this for looping.

 For Each myTable In crReportDocument.Database.Tables
 myLogin = myTable.LogOnInfo
 myLogin.ConnectionInfo.Password = ConfigurationSettings.AppSettings("DevSQLPassword")             myLogin.ConnectionInfo.UserID = ConfigurationSettings.AppSettings("DevSQLUserID")
 myTable.ApplyLogOnInfo(myLogin)
 Next


thanks
0
 
Bob LearnedCommented:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Dim crReportDocument As CrystalReport1 = New CrystalReport1()
Dim crTableLogOnInfo As TableLogOnInfo = New TableLogOnInfo()
Dim crConnectionInfo As ConnectionInfo = New ConnectionInfo()
Dim crDatabase As CrystalDecisions.CrystalReports.Engine.Database
Dim crTables As CrystalDecisions.CrystalReports.Engine.Tables
Dim crTable As CrystalDecisions.CrystalReports.Engine.Table

crConnectionInfo.ServerName = "EnterServerNameHere"
crConnectionInfo.DatabaseName = "EnterDatabaseNameHere"
crConnectionInfo.UserID = "EnterUserIDHere"
crConnectionInfo.Password = "EnterPasswordHere"
crDatabase = crReportDocument.Database
crTables = crDatabase.Tables

For Each crTable In crTables

 crTableLogOnInfo = crTable.LogOnInfo
 crTableLogOnInfo.ConnectionInfo = crConnectionInfo
 crTable.ApplyLogOnInfo(crTableLogOnInfo)

Next

CrystalReportViewer1.ReportSource = crReportDocument

Bob
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now