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

Crystal Reports in VC++

Status
Not open for further replies.

hne

Programmer
Oct 16, 2003
38
US
. . .
.
.
#import "mycrpt.dll" no_namespace
CString strQuery;
IApplicationPtr pApp;
IReportPtr pReport;
VARIANT var;

strQuery.Empty();
strQuery.AllocSysString();
strQuery.Format("select "
"FlightID, FltNbr, FltDate, AlName, "
"LastDepart, ShipNbr, Routing, Destination, "
"HumanRem, LiveAnimals, Notes1, OAL_Flight_Nbr,"
"FlightID, Type, Status, "
"Verified, DeltaEmp, SSRCodes "
"from "
"Flight Flight, "
"PsgrFltData PsgrFltData "
"where "
"FlightID = FlightID AND "
"Status = 'ON' ");

CoInitialize(NULL);

pApp.CreateInstance("CrystalRuntime.Application");
pReport = pApp->OpenReport("filename.rpt", var);
HRESULT hr = pApp->LogOnServerEx("pdsodbc.dll", b_svr, "", b_usr, b_psw);
if (SUCCEEDED(hr))
{ // Dispose of BSTRs...
SysFreeString(b_svr);
SysFreeString(b_usr);
SysFreeString(b_psw);
}
_bstr_t query = strQuery.AllocSysString();
pReport->PutSQLQueryString(query); // apply the modified SQL Query
UpdateData(TRUE); //refresh and update the dialog's data
m_rpViewer.SetReportSource(pReport); // m_rpView is my Crystal Report Viewer control...
m_rpViewer.PrintReport();
m_rpViewer.ViewReport();
m_rpViewer.Zoom(100);

pApp.Release();
pReport.Release();
pReport = NULL;
pApp = NULL;
strQuery.ReleaseBuffer();
. . .
.
.
.
I don't get it. I created the instance, logged on, SetReportSource to my CR Viewer. However, when I view my report, the data is not there. If I run the command from SQL Plus, I can see my data. I have created the fields in my .rpt file. Please help. Thx.
 
are you using Oracle?

Ion Filipski
1c.bmp
 
Yes. I am using Oracle 8.1 Connection to the database is no problem. However, when I run the pReport->PutSQLQueryString(query) command, the application bombs out on me with the error: "First-chance exception in consolee.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception." If I exclude this command, I don't see the data in my report.

Thx.
 
how do you connect to oracle? I mean what kind of drievr have you specified in ODBC when set up the DSN?

Ion Filipski
1c.bmp
 
First, I apologize, I am using Oracle 9, with WinXP. (I have 8.01 installed on my NT test system). Anyway, I specified the 'Oracle in OraHome92, ver. 9.02, file - SQORA32.DLL'. In the NT test system, I am using the same driver, except it is Oracle version 8.01. Thx.
 
I see there two queries, the strQuery and the query. How do you create variable query?

Ion Filipski
1c.bmp
 
'strQuery' is a CString variable and 'query' is a _bstr_t variable. To manipulate the PutSQLQueryString function, I must pass a _bstr_t variable. Therefore, convert 'strQuery' (which allocates a BSTR from CString data), copy 'strQuery' to 'query' and pass the PutSQLQueryString function (which should apply my modified SQL Query).
 
I think it is because of destructor of the variable query. The CrystalReport takes control of your query since you call
PutSQLQueryString. When in terminates working with query, it try to free something what is freed already by clas _bstr_t. Use PutSQLQueryString:):SysAllocString((BSTR)query)); or PutSQLQueryString(query.Detach())

Ion Filipski
1c.bmp
 
Thanks for the help. Mentioning destructor got me thinking that I needed to do a little cleaning up on my code. That did the trick! I do have another question.

I am instantiating RDC several times, since I have several reports to open and view. However, when I 'SetReportSource', I get the error "This value is write-only". I get this only when I attempt to 'SetReportSource' on my second object. Am I missing something when I attempt to open and view several reports? Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top