Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb.net and crystal reports

Status
Not open for further replies.

mkohl

Programmer
Feb 22, 2005
82
US
I wrote a program in vb.net that accesses a microsoft access table. The problem I have is the user creates the database, and table through the vb.net program. So, I would never know what the table name or database name is until runtime.

My question is how can I create a report that doesn't specify a database or table at design time, since the name and the table can change at any given moment. The only thing that is static is each column in the table.

-mike
 
Yeah this is doable


Basically you can create an ADO.net dataset at runtime and use that as the reports datasource. The code to create the dataset is fairly simple

Creating Dataset

Dim data as New DataSet("ReportName")
DIm Table as New DataTable("TableName")

Table.Columns.Add(New DataColumn("PrimaryKey",getType(Integer))
Table.Columns.Add(

ect..

After creating the dataset you will set to tell the report you want to report off this thing. Call data.WriteXML("FILENAME.xsd") to create an xsd schema that holds the stucture off your dataset. Then open the report in the CR.Net designer, go to Add/Remove Datasbase. You will see many choices to report from, go to the bottom (More Data sources\ADO.Net(XML)). Note that changing table or column names will be a pain after you've desinged you're report, try to get the names all right the first time. The dataset you pass to the report will always have to the exact same table and column names as the schema you just passed to the report, or else you will get a Query Engine Error and very little information about why it's wrong.


Then you have to populate the dataset, so you'll need to be able to read data from this table whose name you don't know. I wouldn't want to code this but it's certainly possible. After you read in the data, fill the dataset you created. After filling the dataset, set it a the report's datasrouce.


dim report as New CrystalDecisions.CrystalReports.Engine.ReportClass

report.SetDatasource(data)
 
Thanks for your response. I was hoping to give the user the flexability of nameing the tables and databases they will be populating, but I'm really starting to think that this is probably not the best solution since I want to generate a daily report using crystal reports.

Thanks again, for your time.

-mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top