+ All Categories
Home > Documents > Data Reprots

Data Reprots

Date post: 04-Jun-2018
Category:
Upload: manoj-kavedia
View: 219 times
Download: 0 times
Share this document with a friend

of 40

Transcript
  • 8/13/2019 Data Reprots

    1/40

    Visual basic allows you to add a database environment just the way you add a form. A

    data environment desigener is an ActiveX designer tool provided by Visual basic.A data

    environment designer provide a interactive design time environment to access data from adatabase at run time.A data environment enable to perform following task:

    1. Rightclick at the project in the project e!plorer whence a popup menu appears .". #lick at the add option when a list of insertable objects is displayed.

    $. #hoose data environment when one is added with a default name %dataenvironment1.you can always change the name to your choice by setting its

    properties in the property window. :

    &. 'ata environment opens a connection to the source database . however (you will have

    to set it up manually . )et us change the name of the connection1 to *y#onnection1simply type the same in the +,ame- property as shown below.

    http://www.computernotes.in/wp-content/uploads/2013/04/datare11.jpg
  • 8/13/2019 Data Reprots

    2/40

    . /he connection object of the data environment component has a number of properties

    that can be set to provide different functionalities to the component.

    0. ou can connect to a desired database by the following step:

    http://www.computernotes.in/wp-content/uploads/2013/04/data12.jpg
  • 8/13/2019 Data Reprots

    3/40

    2. Right click at the *y#onnection1 or whichever connection you have./he popmenu

    shown below appeare from where you can choose properties.

    3.4hen you click on properties5 a dialog bo! shown below./his dialog bo! helps you

    set the database link to his connection.6t lists all the types of database drivers currentlyinstalled on your machine.A typical dialog bo! appeares as shown below:

    http://www.computernotes.in/wp-content/uploads/2013/04/DATA13.jpg
  • 8/13/2019 Data Reprots

    4/40

    7. 8elect the 'river *icrosoft 9et &. ;)< '= >rovider.

    http://www.computernotes.in/wp-content/uploads/2013/04/DATA14.jpg
  • 8/13/2019 Data Reprots

    5/40

    1. ,e!t(click at the #onnection tab of the dialog bo!./he #onnection tab opens up as

    shown below:

    http://www.computernotes.in/wp-content/uploads/2013/04/data15.jpg
  • 8/13/2019 Data Reprots

    6/40

    11. 8elect the *icrosoft Access database you wish to connect to by clicking at buttonplace on the right side of the te!tbo! in which you enter the name of the database./he

    database name is shown in the te!tbo! shown in figure above.

    1".,ow(you can test whether your connection was establised cooectly by clicking at /est#onnection button as shown below:

    http://www.computernotes.in/wp-content/uploads/2013/04/data16.jpg
  • 8/13/2019 Data Reprots

    7/40

    1$. 6f the connection could not be established you will get the message for the same.,owyour application is ready to use this connection to interact with the database.

    4hen the connection is create( we can create 'ataReports.

    How you can create DataReports:-

    A database contains a number of objects like tables(?ueries.when you have created a

    connection to the desired database(you need to select the table in the databese from which

    the data will be fetch in the report./o do this right click at your data environment objectand click at Add #ommand as shown below:

    http://www.computernotes.in/wp-content/uploads/2013/04/data18.jpg
  • 8/13/2019 Data Reprots

    8/40

    ". A command object with the default name command1 is added to the data environment

    as shown below:

    http://www.computernotes.in/wp-content/uploads/2013/04/data19.jpg
  • 8/13/2019 Data Reprots

    9/40

    $.#hange #ommand@s name to *y#ommand1 in the properties window.

    &. 8et the command to obtain data from a table from the connection database./o do this

    right click at *y#ommand1 and select properties.A dialog bo! will appeare as shownbelow:

    . 6n this dialog bo! set the desired 'atabase ;bject like /able from where you wish to

    get the data.so(we will take our data from a table/able1.

    0. Alternatively(you can write an 8) statement for this command object by clicking8) statement option button.

    http://www.computernotes.in/wp-content/uploads/2013/04/data21.jpg
  • 8/13/2019 Data Reprots

    10/40

    2.6n case of /able object table fields are shown in *y#ommand1 command object asshown in figure below:

    http://www.computernotes.in/wp-content/uploads/2013/04/data22.jpg
  • 8/13/2019 Data Reprots

    11/40

    http://www.computernotes.in/wp-content/uploads/2013/04/data23.jpg
  • 8/13/2019 Data Reprots

    12/40

    3.,ow you are ready to design your report./o include a report in your apllication add one'ata Report object in the >roject

    7. A data report form is added to the project and displayed for modification .#hange the

    name of this data report to *yReport1 into the property bo! as shown below.

    http://www.computernotes.in/wp-content/uploads/2013/04/datare111.jpg
  • 8/13/2019 Data Reprots

    13/40

    1./o bind it to the data source *y'ata8ource1(click at 'ata8ource property of the

    report and select the data environment *y'ata8ource as shown below.

    http://www.computernotes.in/wp-content/uploads/2013/04/datare62.jpghttp://www.computernotes.in/wp-content/uploads/2013/04/datare2.jpg
  • 8/13/2019 Data Reprots

    14/40

    11. ,ow( your report knows from where it has to fetch its data./o select the sourceobject(set the 'ata*ember property to *y#ommand1 in the property bo! of the report as

    shown below:

    1". ,ow( you are ready to create your report(for this there are two way in Visual =asic.6n Birst way(open the 'ataroject menu.

    http://www.computernotes.in/wp-content/uploads/2013/04/datare33.jpg
  • 8/13/2019 Data Reprots

    15/40

    8et the 8trup ;bject to 'ataReport1.,ow run the project to show the report.;utput isshown below.

    http://www.computernotes.in/wp-content/uploads/2013/04/datare3.jpg
  • 8/13/2019 Data Reprots

    16/40

    http://www.computernotes.in/wp-content/uploads/2013/04/datare9.jpg
  • 8/13/2019 Data Reprots

    17/40

    /he second way( =y adding a command button to a form and writing some code to open

    the report at its event click procedure.Bor this click open the Borm1 to add a command

    button as shown below.

    'ouble click at the command button to open its event procedur. Add the code for opening

    the report as shown below:

    #lick open the project property bo! from >roject menu .8et the 8trup ;bject to

    http://www.computernotes.in/wp-content/uploads/2013/04/datare13.jpghttp://www.computernotes.in/wp-content/uploads/2013/04/datare12.jpg
  • 8/13/2019 Data Reprots

    18/40

    Borm1.,ow run the project Brom1 should be displayed.#lick at the command button to

    show the report.;utput is given below:

    http://www.computernotes.in/wp-content/uploads/2013/04/datare14.jpg
  • 8/13/2019 Data Reprots

    19/40

    'ata Report

    40.1 A brief introduction to reporting tool in Visualbasic 6

    You have learned how to build a database in Visual Basic 6 in previous chapters, howeveryou have not learned how to display the saved data in a report. eports are i!portant anduseful in !any respects because they provide useful and !eaningful infor!ationconcerning a set of data. "n this chapter, we will show you how to create a report in VisualBasic 6.

    "n previous versions of Visual Basic 6, there is no pri!ary reporting . #revious versions ofVisual basic 6 uses $rystal eports tool, a software fro! %eagate. &ortunately, 'icrosofthas integrated a good report writer into Visual Basic 6, so you no longer need to use$rystal eport.

    40.( %teps in building your report in Visual Basic 6

    Visual Basic 6 provides you with a data report designer to create your report, it is somewhatsimilar to data report designer in Microsoft Access. The data report designer has its own set ofcontrols which allow you to customize your report seamlessly. The steps in creating the reportin VB6 are listed below

    %tep 1) Adding *ata eport

    !tart Visual Basic as a !tandard "#" pro$ect. %rom the #ro+ectmenu in the VB", select Add*ata eportin the dropdown menu. &ow, you will be presented with the data reportenvironment, as shown in %igure '(.). The data report environment contains si* controls, theyare +ptTe*tBo*, +ptine, +pt%unction, +ptabel, +pt-mage and +pt!hape.

    ou can customize your report here by adding a title to the page header using the report label+ptabel. !imply drag and draw the +ptabel control on the data report designer window anduse the /aption property to change the te*t that should be displayed. ou can also addgraphics to the report using the +pt-mage control.

  • 8/13/2019 Data Reprots

    20/40

    &igure 40.1) he *ata eport -nviron!ent

    %tep () $onnecting the report to database using *ata -nviron!ent *esigner

    $lic the #ro+ect !enu, then select *ata -nviron!ent. fro! the drop/down !enu. hedefault data environ!ent will appear, as shown in figure 40.(

  • 8/13/2019 Data Reprots

    21/40

    &igure 40.() *ata -nviron!ent

    ow, to connect to the database, right/clic connection1 and select 'icrosoft et 2.315- *B #rovider as we are using '% Access database7 fro! the *ata 5in #ropertiesdialog as shown in &igure 40.27, then clic ne8t.

    &igure 40.2

  • 8/13/2019 Data Reprots

    22/40

    ow, you need to connect to the database by selecting a database file fro! your hard dis.&or de!onstration purpose, we will use the database B"B5".'*B that co!es with VisualBasic, as shown in &igure 40.4. he path to this database file is $)9#rogra! &iles9'icrosoftVisual %tudio9VB:;9B"B5".'*B. his path varies fro! co!puters to co!puters,depending on where you install the file. After selecting the file, you need to test theconnection by clicing the est $onnection button at the right botto! of the *ata 5in#roperties dialog. "f the connection is successful, a !essage that says uery to retrieve theinfor!ation fro! the database. ?ere , we will use %@5 co!!and to create the >uery. &irstof all, right clic on 'y$onnection to add a co!!and to the data environ!ent. he defaultco!!and is $o!!and1, you can rena!e it as 'y$o!!and, as shown in &igure 40.3.

  • 8/13/2019 Data Reprots

    23/40

  • 8/13/2019 Data Reprots

    24/40

    &igure 40.6) #roperties of

    o add data to your report, you need to drag the fields fro! 'y$o!!and in'y*ata-nviron!ent into 'y*ataeport, as shown in &igure 40.D.Visual Basic 6 willauto!atically draw a pte8tBo8, along with a pt5abel control for each field on thereport. You can custo!iCe the loo of the labels as well as the e8tBo8es fro! theproperties window of 'y*ataeport.

  • 8/13/2019 Data Reprots

    25/40

    &igure 40.D

    he &inal step is to set 'ydataeport as the %tartup for! fro! the #ro+ect !enu, then runthe progra!. You will see your report as shown in &igure 40.;. You can print out yourreport.

  • 8/13/2019 Data Reprots

    26/40

  • 8/13/2019 Data Reprots

    27/40

    *ata -nviron!ent

    6n this chapter( we will understand how to use 'ata

    1. 8elect >rojectF Add 'ata

  • 8/13/2019 Data Reprots

    28/40

    $. 8elect the re?uired ;)rovider-

    &. 8elect #onnection tab and select the name of the database + =6=)6;.*'=-

    . #lick on ;k/o rename connection object:

    1. 6nvoke popup menu by click on #onnection object with right button.". 8elect Rename option.

    $.

  • 8/13/2019 Data Reprots

    29/40

    Eierarchical Ble!Crid control and 'ata Report object.

    /o create command object for >ublishers:

    1. 8elect connection object( =iblio( and click on right button to invoke popup menu and

    select Add #ommand option of popup menu.". After a command object is created invoke its properties by selecting >roperties option

    from >opup menu.

    $. #hange ,ame of the command object to >ublishers&. #hoose /able as the 'atabase ;bject and select >ublishers as the name of the object.

    . #lick on ;k.

    /o create child command object for /itles:

    1. 8elect >ublishers command object and invoke popup menu.

    ". 8elect Add #hild #ommand option.

    $. A new command object is created and placed along with fields of >ublishers commandobject.

    &. 8elect #hild command object and invoke its properties. #hange name to /itles.

    0. #hoose /able as 'atabase ;bject and /itles as the name of the database object.

    2. #lick on Relation tab to set relationship between >ublishers and /itles commandobject.

    3. *ake sure >arent Bields and #hild Bields are set to >ub6' and click on Add button to

    establish relationship between >ublishers and /itles based on >ub6d field.

    7. #lick on ;k.

    After child object is created( 'ata

  • 8/13/2019 Data Reprots

    30/40

  • 8/13/2019 Data Reprots

    31/40

    ,ote: 8ee 8ample 'ata

  • 8/13/2019 Data Reprots

    32/40

    'ataCrid control

    8croll 8crolls the 'ataCrid control horiMontally and vertically in a single operation. ou

    have to specify the number of rows and number of columns to scroll./able ".": *ethods of 'ataCrid control.

    /o put an image of the 'ataCrid in an image bo!:

    6mage1.picture N 'ataCrid1.capture6mage

    /o get the row and columns of the current mouse pointer:

    X and are coordinates of *ouse pointer

    RowValue N 'ataCrid1.Row#ontaining+-

    colValue N 'ataCrid1.#ol#ontaining+X-

    >roperties of 'ataCrid control/he following are important properties of 'ataCrid.

    >roperty *eaningAllowArrows 8ets or returns a value that determines whether the control uses the arrow

    keys for grid navigation.

    Apro!#ount Returns the appro!imate number of rows in the grid.

    #urrent#ell*odified 8ets or returns modification status of the current cell. 6f it is true( itmeans current cell( identified by =ook*ark and #ol properties( is modified.

    #urrent#ellVisible Returns true if current cell is visible.

  • 8/13/2019 Data Reprots

    33/40

    VisibleRows Returns the number of visible rows.

    RowEeight 8ets the height of all rows in datagrid.

    /able ".$: >roperties of 'ataCrid control.

    rivate 8ub 'ataCrid1P=efore#olIpdate +#ol6nde! As )ong( ;ldValue As

  • 8/13/2019 Data Reprots

    34/40

    Variant( #ancel As 6nteger-

    6f #ol6nde! N 1 /hen

    6f 'ataCrid1.#olumns+1-.Value S ,ow /hen #ancel N /rue *sg=o! Qou must enter adate that is later than today.Q roject F Add 'ata roducts.

    &. #lick right mouse button on #onnection object to invoke popup menu and selectproperties option to invoke 'ata )ink >roperties.

    . 8elect *icrosoft 9et $.1 ;)< '= >rovider as ;)< '= provider.0. 8elect #onnection tab and choose >roducts.mdb as the database.

    2. #lick on ;G to close 'ata )ink >roperties.

    3. 6nvoke popup menu of #onnection object and select Add #ommand to add a commandobject.

    7. A new #ommand object will be created with the name #ommand1.

    1. 8elect #ommand object and invoke its properties.

    11. #hange the following properties of the command1 object.,ame >roducts

    'atabase ;bject /able

    ;bject ,ame >roducts

    1". 6nvoke popup menu of #onnection object again and select Add #ommand option.

    1$. A new command object will be created again.1&. #hange the following properties of the newly created command object.

    ,ame 8ales

    'atabase ;bject /able;bject ,ame 8ales

    After both the command objects are created( the 'ata

  • 8/13/2019 Data Reprots

    35/40

  • 8/13/2019 Data Reprots

    36/40

    >roperty Value

    ,ame 'cmb>rodno

    =ound#olumn >rodno)istBield >roddesc

    'ataBield >rodno

    'ata*ember 8ales'ata8ource 'envproducts

    Row8ource 'envproducts

    Row*ember >roducts8tyle "dbc'ropdownlist

    'ata#ombo bo! is used to get the list of products from >roducts command of 'ata

  • 8/13/2019 Data Reprots

    37/40

  • 8/13/2019 Data Reprots

    38/40

    same product.

    8electing #lose button of frm>rod)ist #loses the form and returns to ?ty8old field of

    frm8ales./able ".: rivate 8ub cmd#ancelP#lick+-4ith 'env>roducts.rs8ales

    .#ancelIpdate

    .Add,ew

    #learBields

  • 8/13/2019 Data Reprots

    39/40

    >rivate 8ub BormPActivate+-

    4ith 'env>roducts.rs8ales6f .6f ,ot checkP?ty /hen#ancel N /rue

  • 8/13/2019 Data Reprots

    40/40


Recommended