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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error detected by database DLL 1

Status
Not open for further replies.

shaminda

Programmer
Joined
Jun 9, 2000
Messages
170
Location
US
I created a Crystal Reports 8.5 report and linked a text file using ODBC. Initially after I created the report and I previewed the report and it worked fine. Then I have a visual basic 6.0 program that writes to the text file and prints the report. But when I try to print it gives me an error message. Then afterwards if I try to open the report and try to preview it, it gives me the following errors

ODBC error:[Microsoft][ODBC Text Driver]Too few parameters. Expected 1.

And

Error detected by database DLL.

The error I get on the VB side is

Run-time error ‘20534’: Error detected by database DLL
 
So, the problem is not with the Crystal report. It's with your odbc connection. I would suggest visiting Microsoft's site to determine the causes of the ODBC error messgage.

But I would also ask why are you writing out to a text file and then trying to have Crystal use the text file as a datasource? It seems unnecessary. If you have the data in a recordset or an array in vb prior to writing it to the text file, you could simply pass the recordset or array to the report rather than requiring the report to have connectivity to the text file. There are two different, albeit similar, approaches, depending on whether or not the data is in a recordset or array, but sending the data directly from vb to Crystal would be much more efficient and easier to troubleshoot. If you are interested in bypassing the text file as a datasource and passing the data straight from vb into the report, let me know.
 
I am new to crystal report and I thought using a text file would be the easiest way. Yes I would be interested in bypassing the text file and pass the data straight to crystal reports.
 
Will the data in your vb app be in an ado recordset or in an array?
 
FVTrainer,
Thank you for your quick responses. The Tek-tips site was down all day yesterday so I couldn't do much.
The data are in two arrays. One array is a string array the other is an integer array. Both are of size 15. Here is an example of my data

Part Description Quantity
8654 Black 5
8234 Brown 0
7865 Blue 56
6789 Red 24

 
Well, you'll need to get the data into a single array, which shouldn't be too difficult. Once you've done that in code, then you need to do the following:

1) In Crystal, your report needs to be designed to use the Crystal Data Object (CDO). When first creating the report, use the Data Explorer and open the "More Data Sources" folder. Select "Active Data", then "Field Definitions Only" (Actually, if you can write a SQL statement that will return a dataset identical in schema to what is in your array, you could use "Active Data (ADO)", which would make it a little easier to build your report). At the bottom of the field definitions screen, click the New button and define the field names and data types that will be used in the report. Use the "File" menu option in the small field definition screen to save the file, then close it and make sure you double-click on it in the data explorer to add it as a datasource for your report.

2) Create your report.

3) In vb, you need to create a Crystal CDO object, as well as the Crystal report object you are already creating. The CDO takes an array. So you create CDO object, define the array elements it will use, and then pass it an array. Some sample code is given below:

Dim crApp As New CRAXDRT.Application
Dim crRpt As CRAXDRT.Report

Private Sub Form_Load()

Dim crArea As CRAXDRT.Area
Dim crCDO As New CrystalDataObject.CrystalComObject
Dim x As Integer
Dim y As Integer


Set crRpt = crApp.OpenReport(App.Path & "/CDO_Sample_Report.rpt ")

crCDO.AddField "Customer Name", vbString
crCDO.AddField "Last Year's Sales", vbNumber

Dim Rows(5, 1) As Variant '6 rows with 2 columns - zero-based array

Rows(0, 0) = "George Washington"
Rows(0, 1) = 2000
Rows(1, 0) = "John Adams"
Rows(1, 1) = 4000
Rows(2, 0) = "Thomas Jefferson"
Rows(2, 1) = 4500
Rows(3, 0) = "James Madison"
Rows(3, 1) = 3000
Rows(4, 0) = "John Q. Adams"
Rows(4, 1) = 3500
Rows(5, 0) = "Alexander Hamilton"
Rows(5, 1) = 200

'Here is where the array gets passed to the CDO
crCDO.AddRows Rows

crRpt.DiscardSavedData
crRpt.Database.Tables(1).SetDataSource crDCO, 3

CRViewer1.ReportSource = crRpt
Me.WindowState = 2
CRViewer1.ViewReport


I know that is a lot of info, and it may look intimidating. Just take it a step at a time. Let me know if you need any clarifications.
 
FVTrainer,
I am getting an error at the following line

crRpt.Database.Tables(1).SetDataSource crDCO, 3

and the error is

Run-time error ‘445’
Object Doesn’t support this action

Could you also explain what that line does.

Thank you!
 
Ooops. The line should be:

crRpt.Database.Tables(1).SetDataSource crCDO, 3

Your report doesn't have any database connectivity; it receives a recordset, in the form of an array, from your vb app. This line passes the CDO object (crCDO), or array, to the Crystal report. It tells the table in the report that it's datasource is not an external source, but rather this CDO object.
 
Ok I am not sure what I am missing. I created a .ttx file with two feilds and I droped those feilds to the report. Did I create the report wrong?
 
So, what is the problem? Are you getting an error message when you try to open the report? Are you getting a blank screen?

In the face of it, it doesn't sound link there is anything wrong with your report. You should be doing the following steps in your vb code:

1)Create the report object.
2)Create the CDO object.
3)Create an array and populate it.
4)Pass the array to the CDO object.
5)Pass the CDO object to the report.

If you want a working sample of a cdo vb project, click on the following link:

 
FVTrainer,
Thank you very much for your help. I got it running. I had CrDCO instead of CRCDO.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top