on 08-01-2023 9:15 AM
The main objective is to rename/replace one or more Database tables currently present in RPT file with another table with same structure and field names, at run time.
I am trying to retrieve SQL query from RPT file , edit it (replacing a table with another or rename) and set this SQL query back to RPT file. After that calling Export method to create a pdf report out of it.
I am using C++\CLI with VS 2022.
Following is my code:
String^ fReportFile = gcnew String(aFileName);
gReport = gcnew ReportDocument();
//calling load report function of Reportdocument class
gReport->Load(fReportFile);
bool bConn= ConnectDataSource(gReport, aUserId, aPassword, aServer, aDatabase, false, aErrorLog);
gRowsetController = gReport->ReportClientDocument->RowsetController;
gGroupPath = gcnew GroupPathClass();
String^ strRPTSQLQuery;
String^ strSqlQuery = gRowsetController->GetSQLStatement(gGroupPath, strRPTSQLQuery); // here I am able to retrieve the query and modified it:
strSqlQuery = strSqlQuery->Replace("ItemMG", "Trade");
connectionString = "data source=" + ServerName+"; initial catalog = " + fConnectionInfo->DatabaseName + "; user id = " +
fConnectionInfo->UserID +"; password = " + fConnectionInfo->Password;
cnn = gcnew SqlConnection(connectionString);
cnn->Open();
SqlDataAdapter^ sqlDataAdapter = gcnew SqlDataAdapter(strSqlQuery, cnn);
System::Data::DataSet^ ds= gcnew System::Data::DataSet();
sqlDataAdapter->Fill(ds);
cnn->Close();
gReport->SetDataSource(ds); // till here it works and ds contains the correct query data
BUT after this when I call, Export method still uses initial query which was there in RPT instead of modified one:
//Export Report
gReport->Export();
Please help resolve this issue as I want to change the tables at runtime.
Thanks in advance,
Anoop
Yes, joined tables in database expert.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.