Use RAVE report in Delphi 7 (6)

xiaoxiao2021-03-06  40

Use RAVE report in Delphi 7 (6)

- Reports for database connections (2)

In Delphi 7, use the RAVE report (5) to explain the reports of the database connection, and some friends have issued a problem, so use an article to explain the report using the Query dynamic query and stored procedure to connect the database. Because we want to use the stored procedure, we use the SQL_SERVER2000 database to create Database INFOTEST, establish a data sheet Infotable field to: {[Name], [SEX], [AGE], [PROVINCE]}, add data. The part of the database is not explained too much. Place the Database, Query, DataSource, RVQueryConnection, DBGRID components on the form, connect to the database, {Query all [Shaanxi]} button Events: Procedure TFORM1.BUTTON1CLICK (Sender: TOBJECT); begin query1.sql.clear; Query1.sql.add ('selection =: pro)'); query1.parambyname ('pro'). Asstring: = 'Shaanxi'; query1.execsql; query1.active: = true;

After running Click, you can check that DBGrid shows the result of viewing, which completed the first step ------ Dynamic query process. Run the program, [Query], then open RAVE, remember not to turn off the query. [File] => new data object => DIRECT DATA View => Select RVQueryConnection1 => [FINISH] => See the Data View Dictionary of the report design Navigation area Add DataView1, you can see the data field after the extension; select [Tools] => Report wizards => Single Table => Select DataView1, select Database Field => Report Title to "Personal Status". Ok, you can see the report in Page.

Then, save the * .rav file closes the program, add the [Report Preview] button event. And the GetCols and GetRow events of RVQueryConnection1. procedure TForm1.Button2Click (Sender: TObject); begin With RvProject1.ProjMan do begin RvProject1.Open; RvQueryConnection1.ExecGetCols; // get the column names RvQueryConnection1.ExecGetRow; // get record RvProject1.ExecuteReport ( 'Report2'); Close; end ;

procedure TForm1.RvQueryConnection1GetCols (Connection: TRvCustomConnection); begin Connection.WriteField ( 'name', dtString, 10, '', ''); Connection.WriteField ( 'sex', dtString, 6, '', ''); Connection .Writefield ('Age', DTINTEGER, 6, '', '); Connection.Writefield (' province ', dtstring, 10,' ','); end;

procedure TForm1.RvQueryConnection1GetRow (Connection: TRvCustomConnection); begin Connection.WriteStrdata ( '', DBGrid1.Fields [0] .value); Connection.WriteStrdata ( '', DBGrid1.Fields [1] .value); Connection.WriteIntdata ( ' ', Dbgrid1.fields [2] .value); connection.writestrdata (' ', dbgrid1.fields [3] .value); end; running the program, this completes a report generated according to the dynamic query. The report method using the stored procedure is as follows: First, you have to build your stored procedure, build the store as follows, although this simple query stored procedure is not necessary, here is just a simple example: alter procedure pra_testasDeclare @chrnsql nvarchar (1000) SELECT @ chrnsql = 'select * from infotable where ag> 21'Exec sp_executesql @chrnsql In the previous program, add DBGRID2, StoredProc1, DataSource2, RVDataSetConnection1, [Run Storage Procedure] button, and [Report Preview] buttons. DataSource2's DataSet property is set to StoredProc1, DataSource for DBGRID2 is set to DataSource2. StoredProc1 connected database, StoredProcName: = 'pr_test'; dataset property RvDataSetConnection1 to StoredProc1, [run a stored procedure] click button event is: with StoredProc1 do begin prepare; StoredProc1.Active: = True; end; procedure run, see DBGRID2 shows the results of the stored procedure query. Run the program, [Run Store], then open Rave, remember not to turn off the query. Then, use the same method as the above example, add the following code: [file] => new data object => Direct data view => Select RVDataSetConnection1 => [Finish] => See the Data View Dictionary of the report design navigation area Added DataView2, you can see the data field after the expansion; select [Tools] àreport wizardsàsingle Tableà Select DataView2, select Database Field àreport Title to "Personal Situation". Ok, you can see the report in Page. Save the file, close the program, add the [Report Preview] button event. And the getCols and GetRow events of RVDataSetConnection1.

procedure TForm1.Button4Click (Sender: TObject); begin With RvProject1.ProjMan do begin RvProject1.Open; RvDataSetConnection1.ExecGetCols; // get the column names RvDataSetConnection1.ExecGetRow; // get record RvProject1.ExecuteReport ( 'Report3'); Close; end ; end; procedure TForm1.RvDataSetConnection1GetCols (Connection: TRvCustomConnection); begin Connection.WriteField ( 'name', dtString, 10, '', ''); {Listing} Connection.WriteField ( 'sex', dtString, 6, ' ',' '); Connection.writefield (' agnte, dtinteger, 6, '', '); connection.writefield (' province ', dtstring, 10,' '); end; procedure tForm1.rvdatasetConnection1Getrow (Connection: TRvCustomConnection); begin Connection.WriteStrdata ( '', DBGrid2.Fields [0] .value); Connection.WriteStrdata ( '', DBGrid2.Fields [1] .value); Connection.WriteIntdata ( '', DBGrid2. Fields [2] .value; connection.writestrdata ('', dbgrid2.fields [3] .value); end; ok, this explanation should be designed with the report related to the database, summarize: Get the result of the query by DBGRID data sensing components, through and RAVE connection components (RVDAT ASETCONNECTION, RVQueryConnection, etc., GetCols, and getRow events add data to the report.

(PS: Please indicate the author - the fish (CYQ) on the highway)

转载请注明原文地址:https://www.9cbs.com/read-69340.html

New Post(0)