Page 268 - Open Soource Technologies 304.indd
P. 268

Event Driven Programming



                          Because the File Name argument causes ADO to load the associated provider, you cannot pass both
                          the  Provider and  File Name arguments.
                          The  ConnectionString property is read/write when the connection is closed and read-only when
                          it is open.
                          Duplicates of an argument in the ConnectionString property are ignored. The last instance of any
                          argument is used.

                          12.3  Displaying Data from Database in Grid
                          We will start Visual Basic and insert an ADO control, a DataGrid and three command buttons.
                          Name the three command buttons as  cmdAuthor,  cmdTitle  and cmdAll. Change their captions
                          to  Display Author ,Display Book Title and  Display All respectively. The design interface is
                          shown in Figure 12.1.























                                             Figure 12.1: Displaying Data from Database in Grid.

                           Now you need to connect the database to the ADO data control. However, you need to make
                          one change. At the ADODC property pages dialog box, click on the Recordsource tab and select
                          1-adCmdText  under command type and under Command Text(SQL) key in  SELECT * FROM
                          book.
                          Next, click on the command buttton cmdAuthor and key in the following statements:
                          Private Sub cmdAuthor_Click()
                          Adodc1.RecordSource = “SELECT Author FROM book”

                          Adodc1.Refresh
                          Adodc1.Caption = Adodc1.RecordSource
                          End Sub
                          and for the command button cmdTitle, key in
                          Private Sub cmdTitle_Click()
                          Adodc1.RecordSource = “SELECT Title FROM book”



                          262                    LOVELY PROFESSIONAL UNIVERSITY
   263   264   265   266   267   268   269   270   271   272   273