Total members 11889 |It is currently Mon Mar 18, 2024 11:52 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





I have been trying to findmout how to generate a dynamic report in visual
basic using crystal report. I know how to design a database program and use
crystal report or data report with dataenvironment or with DSN. Really this does
little compared to what i want. What i need is that when a user select the
fields he/she wants to use or see i want those fields (that means selected field
only) alone to be reported in the crystal report or data report. That is what i
have been trying to find out. Please kindly help me if you can




Author:
Proficient
User avatar Posts: 280
Have thanks: 1 time

How to pass Database logon info to a Crystal Report at runtime in
VB.NET
The information in the article refers to:
Crystal Reports for Visual Studio .NET

Applies to:

Reported version only
Logon Information
TableLogonInfo


Synopsis

A VB.NET application uses Crystal Reports for Visual Studio .NET as
the reporting development tool.

How do you pass database logon information to a Crystal Report at
runtime in this VB.NET application?


Solution

To pass logon information to a Crystal Report at
runtime, use the following code sample:

Code:
VB.NET
---------

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared


Dim crtableLogoninfos As New TableLogOnInfos()
Dim crtableLogoninfo As New TableLogOnInfo()
Dim crConnectionInfo As New ConnectionInfo()
Dim CrTables As Tables
Dim CrTable As Table
Dim TableCounter

'If you are using a Strongly Typed report (Imported in
'your project) named CrystalReport1.rpt use the
'following:

Dim crReportDocument As New CrystalReport1()

'If you are using a Non-Typed report, and
'loading a report outside of the project, use the
'following:

Dim crReportDocument As New ReportDocument()

crReportDocument.Load("c:\myReports\myReport.rpt")

'Set the ConnectionInfo properties for logging on to
'the Database

'If you are using ODBC, this should be the
'DSN name NOT the physical server name. If
'you are NOT using ODBC, this should be the
'physical server name

With crConnectionInfo
.ServerName = "DSN or Server Name"

'If you are connecting to Oracle there is no
'DatabaseName. Use an empty string.
'For example, .DatabaseName = ""

.DatabaseName = "DatabaseName"
.UserID = "Your User ID"
.Password = "Your Password"
End With

'This code works for both user tables and stored
'procedures. Set the CrTables to the Tables collection
'of the report

CrTables = crReportDocument.Database.Tables

'Loop through each table in the report and apply the
'LogonInfo information

For Each CrTable in CrTables
CrTableLogonInfo = CrTable.LogonInfo
CrTableLogonInfo.ConnectionInfo =
crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)

'If your DatabaseName is changing at runtime, specify
'the table location.
'For example, when you are reporting off of a
'Northwind database on SQL server you
'should have the following line of code:

crTable.Location = "Northwind.dbo." &
crTable.Location.Substring(crTable.Location.LastIndexOf(
".") + 1)
Next


'Set the viewer to the report object to be previewed.

CrystalReportViewer1.ReportSource = crReportDocument


Code:
C#.NET
---------

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

private CrystalReport1 crReportDocument = new
CrystalReport1 ();
private Database crDatabase;
private Tables crTables;
private Table crTable;
private TableLogOnInfo crTableLogOnInfo;
private ConnectionInfo crConnectionInfo = new
ConnectionInfo ();

//Setup the connection information structure
//to log on to the data source for the report.
// If using ODBC, this should be the DSN. If using
// OLEDB, etc, this should be the physical server name


crConnectionInfo.ServerName = "DSN or
Server Name";

// If you are connecting to Oracle there is no
// DatabaseName. Use an empty
// string i.e. crConnectionInfo.DatabaseName = "";

crConnectionInfo.DatabaseName = "DatabaseName";
crConnectionInfo.UserID = "Your UserID";
crConnectionInfo.Password = "Your Password";

// This code works for both user tables and stored
//procedures

//Get the table information from the report
crDatabase = crReportDocument.Database;
crTables = crDatabase.Tables;

//Loop through all tables in the report and apply the
//connection information for each table.
for (int i = 0; i < crTables.Count; i++)
{
crTable = crTables [i];
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo =
crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);

//If your DatabaseName is changing at runtime, specify
//the table location. For example, when you are reporting
//off of a Northwind database on SQL server
//you should have the following line of code:

crTable.Location = "Northwind.dbo." +
crTable.Location.Substring(crTable.Location.LastIndexOf
(".") + 1)
}

//Set the viewer to the report object to
//be previewed.

crystalReportViewer1.ReportSource =
crReportDocument;


Additional Information
--------------------------

• If you are using a web application make sure that
you do not specify or call the DataBind in your
code as this will nullify the code above.

• If the above code still results in a logon
failure in a web application (ASP.NET), refer to
knowledge base article c2010867 (For Windows 2000) or
c2013758 (Windows 2003 Server (IIS6)), and ensure
that the ASPNET account has sufficient access to
the database, reports, and the application directories.

• If you are changing database at runtime, it is
important that you specify the table location
after you apply logon information (this is a case
sensitive property). You can either specify the table name
only or the fully qualified table name such as

crTable.location = "databaseName.dbo.tablename"

• Refer to knowledge base article c2010275 if you
wish to change database logon information in the
main and subreport.

• If you are reporting off an Access database, then
specify either the 'ServerName' or 'DatabaseName'
to the 'ConnectionInfo' Object depending on
how you are connecting to Access.

For example, if you are connecting to Access
through ODBC, then set the 'DatabaseName' for the
'ConnectionInfo' object as follows:

With crConnectionInfo
.DatabaseName = "C:\mydatabase\mydata.mdb"
End With

If you are connecting to Access through OLE DB,
then set set the 'ServerName':

With crConnectionInfo
.ServerName = "C:\mydatabase\mydata.mdb"
End With

It is not possible to report of a secured Access
database using a native connection. See knowledge
base article 2010460 for more information.

• If you are using more than one database with
different usernames and passwords, use a loop to
pass in the different values.

_________________
Please recommend my post if you found it helpful


Author:
Proficient
User avatar Posts: 228
Have thanks: 0 time

i know how to generate crystal report in GUI.
By using visual C#...thanks for replies...
now i can generate crystal report with VB.... :think:


Author:
Newbie
User avatar Posts: 27
Have thanks: 1 time

Hello Friend,

Creating a dynamic crystal report, presently API's
supplied by seagate do not allow you to do that.


Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time
Post new topic Reply to topic  [ 4 posts ] 

  Related Posts  to : dynamic crystal report generation
 Crystal report     -  
 crystal report     -  
 About Report Generation     -  
 Crystal report export to excel, page header issue asp.net     -  
 Dynamic Domain Name System (Dynamic DNS )     -  
 Image Files Generation     -  
 Jasper report     -  
 Basic daynamic page generation using CGIs programs     -  
 How make a report using IReport on JSP?     -  
 Jasper Report Java Usage Example     -  



Topic Tags

ASP Reports






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com