Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Management Review for Final (Part 1) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Wednesday 4/30/2003)

Similar presentations


Presentation on theme: "Database Management Review for Final (Part 1) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Wednesday 4/30/2003)"— Presentation transcript:

1 Database Management Review for Final (Part 1) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Wednesday 4/30/2003)

2 2 What is a Database ? n Database: Collection of information stored in tables n Example: BIBLIO.MDB Au_IDAuthorYear Born Authors table (6246 Records, 3 Fields) PubID Name Company Fax Comments Publishers table (727 Records, 10 Fields) Au_ID ISBN Title Author table (16056 Records, 2 Fields)

3 3 Table, Field, Record Authors Table Au_ID Author Year_Born A001 Jacobs, Russell 1945 A002 Metzger, Philip W. 1961A003 Sydow, Dan Parks 1948: : :: : : Field Record

4 4 VB and Database Management n Two tools in VB 6.0 to manage databases – Activex Data Object (ADO) – Data Access Object (DAO) n ADO control should be added to the toolbox (Project/Components… and check Microsoft ADO Data Control) n ADO and DAO controls can be used to: – Connect to a database. – Open a specified database table. – Create a virtual table based on a database query. – Pass database fields to other Visual Basic tools, for display or editing. Such tools are bound tools (controls), or data-aware. – Add new records or update a database.

5 5 DAO control n Common properties: – DatabaseName Used to set the name and location of database – RecordSource Used to set specific table in the database – EOF End of File – BOF Beginning of File – RecordCount Number of records Examples: Name: datBiblio DatabaseSource: C:\Program Files\Microsoft Visual Studio\VB98\BIBLIO.MDB RecordSource: Titles

6 6 Bounding Text boxes to DAO control n Text boxes are said data-aware because they can be bound to DAO controls and access their data n Two Text boxes properties are used to bound them to DAO controls: – DataSourceUsed to set the DAO control from which data is read – DataField Used to set the field of the table from which data is read Examples: Name: txtTitle DataSource: datBiblio DataField: Title Name: TxtYear DataSource: datBiblio DataField: Year_Published

7 7 Exercise n Create the following user-interface with one DAO control and two text boxes so that data in the table Titles from the database BIBLIO.MDB (found in the main VB directory). Name: txtTitle DataSource: datBiblio DataField: Title Name: TxtYear DataSource: datBiblio DataField: Year_Published Name: datBiblio DatabaseSource: C:\Program Files\Microsoft Visual Studio\VB98\BIBLIO.MDB RecordSource: Titles

8 8 ADO control: Methods n Common methods used: – MoveFirst Move to the 1 st record and make it the current record – MoveLast Move to the last record and make it the current record – MoveNext Move to the next record and make it the current record – MovePrevious Move to the previous record and make it the current record – Recordset Used to refer to the content of the table in RecordSource n Recordset.Fields(“FieldName") n Recordset.Fields(" FieldName").Value n Example: datBiblio.Recordset.MoveLast ' Needed to set the value of RecordCount datBiblio.Recordset.MoveFirst For i = 0 To datBiblio.Recordset.RecordCount datBiblio.Recordset.MoveNext Next i

9 9 ADO control: Examples n Example 1 : If EOF is reached, move to the previous record If datBiblio.Recordset.EOF datBiblio.Recordset.MovePrevious End If n Example 2 : Delete the current record datBiblio.Recordset.Delete n Example 3 : Use datBiblio to add items do a list box To be done in class

10 Review For Final (Part 1)

11 Setting properties, Assignment statements

12 12 Statements for setting properties n General rule: ObjectNane.Property = Value Where ObjectName is the name of the Object Property is one of the properties of the object Value is a valid setting for Property Such statements are called Assignment statements

13 13 Setting colors n At design time – Colors are selected from the palette (in Properties Win.) n When writing code – 8 most common colors can be assigned with the following color constants: vbBlackvbRedvbGreenvbYellow vbBluevbMagnetavbCyanvbWhite Example: txtBox.ForeColor = vbGreen

14 14 Assigning Font settings n At design time – Font settings are assigned from the palette (in Properties Win.) n When writing code – Font settings can be assigned using statements like: txtBox.Font.Name = “Courier” txtBox.Font.Name = “Arial” txtBox.Font.Size = 18 lblOne.Font.Italic = True

15 15 Exercises n Exercises 19-32, page 68 Write a line (or lines) of code to carry out the following: n Display “The stuff that dreams are made of.” in red letters in txtBox txtBox.ForeColor = vbRed txtBox.Text = “The stuff that dreams are made of.” n Display “Life is like a box of chocolates.” in Courier font in txtBox txtBox.Text = “Life is like a box of chocolates.” txtBox.Font.Name = “Courier”

16 16 Exercises n Delete the content of txtBox txtBox.Text = “” n Delete the content of lblTwo lblTwo.Caption = “”

17 17 Exercises n Make lblTwo disappear lblTwo.Visible = False n Remove the border from lblTwo lblTwo.BorderStyle = 0 n Give picBox a blue background picBox.BackColor = vbBlue

18 18 Exercises n Place a bold red “Hello” in lblTwo lblTwo.Font.Bold = True lblTwo.ForeColor = vbRed lblTwo.Text = “Hello”

19 19 Exercises n Place a bold italic “Hello” in txtBox txtBox.Font.Bold = True txtBox.Font.Italic = True txtBox.Caption = “Hello” n Make picBox disappear picBox.Visible = False

20 20 Exercises n Give the focus to cmdButtom cmdButton.SetFocus n Remove the border from picBox picBox.BorderStyle = 0

21 21 Exercises n Place a border arround lblTwo and center its content lblTwo.BorderStyle = 1 lblTwo.Alignment = 2 n Give the focus to txtBoxTwo txtBoxTwo.SetFocus

22 Built-in Functions

23 23 Numeric Functions

24 24 Numeric Functions n Examples Sqr (9) is 3Int(2.7) is 2Round(2.7) is 3 Sqr (0) is 0Int(3) is 3 Round(2.317,2) is 2.32 Sqr (2) is 1.4142Int(-2.7) is -3 Round(2.317,1) is 2.3 Private Sub cmdEvaluate_Click() Dim n As Single, root As Single ' Evaluate functions at a variable picResults.Cls n = 6.76 root = Sqr(n) picResults.Print root; Int(n); Round(n, 1) End Sub

25 25 String Functions Left (“String”, n) Returns a string containing a specified number of characters, starting at the beginning of the “String”. Right (“String”, n) Returns a string containing a specified number of characters from the end of the “String”. Mid (“String”, m, n) Returns a string containing a specified number of characters starting at the position indicated by the first number and continuing for the length specified by the second number UCase (“String”) Converts any lowercase letters in string to uppercase LCase (“String”) Converts any uppercase letters in string to lowercase InStr (“Str1”, ”Str2“) Searches for the first occurrence of one string in another and gives the position at which the string is found Len (“String”) Returns the number of characters in the string. Trim (“ String ”) Returns “String” with leading and trailing spaces removed.

26 26 String Functions n Examples Left (“fanatic”, 3) is “fan”Right (“fanatic”, 3) is “tic” Mid (“fanatic”,5,1) is “t” UCase(“Disk”) is “DISK”LCase(“Disk”) is “disk” Trim(“-12 “) is “-12”

27 27 Format Function n The format functions provide detailed control of how numbers, dates, and strings are displayed. n Example: FormatNumber (12345.678, 1) 12,345.6 FormatCurrency (12345.678, 2) $12,345.68 FormatPercent (.185, 2) 18.50% FormatNumber (1 + Sqr(2), 3) 2.414 FormatDateTime(“9-15-99”, vbLongDate) Wednesday, September 15, 1999 Format(1234567890, “@@@@@@@@@@”) 1234567890 Format(FormatNumber(1234.5), “@@@@@@@@@@”) 1,234.50

28 28 Exercises n 1. Given the data in the string variable y shown below, which of the following statements will assign the value ALL to the string variable x? y = "WHEN ALL ELSE FAILS, READ THE DIRECTIONS“ (A)x = Mid(y, 6, 3) (B)x = Left(y, 3) (C)x = Middle(y, 6, 3) (D)x = Right(y, 8)

29 29 Exercises n 2. What will be displayed when the following program is executed? Dim a As String, b As String, c As String a = "THE WHOLE" b = "PART" c = Mid(a, Sqr(4), Len(b)) picBox.Print c (A)THE WHOLE PART (B)6 (C)HE W (D)HOLE (E)None of the above

30 30 Exercises n 3.What will be the output of the following statement? picBox.Print FormatCurrency(1234.567,2) (A)$1234.567 (B)1,234.57 (C)$1234.57 (D)$1,234.57

31 31 Exercises n 4. What will be the output of the following lines? Dim alphabet As String, soup As String alphabet = "abcdefghijklmnopqrstuvwxyz" soup = UCase(alphabet) picBox.Print Left(alphabet, 5); Left(soup, 5) (A)abcdeABCDE (B)ABCDEABCDE (C)eE (D)EE

32 32 Exercises n 5. What output is generated by the following statements (show the output EXACTLY as it would appear)? (A)picBox.Print Sqr(3^2 + 4^2) (B)picBox.Print Mid("Milkshake", 5, 5) (C)picBox.Print UCase("123jump")


Download ppt "Database Management Review for Final (Part 1) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Wednesday 4/30/2003)"

Similar presentations


Ads by Google