Download presentation
Presentation is loading. Please wait.
Published byJob Singleton Modified over 9 years ago
1
Internal connection and introduction to shape language Please use speaker notes for additional information
2
PrStuHier.vbp - version with internal code
3
From student table. From major table. From student course table.
4
Dim comStuHier As ADODB.Connection Dim rsStudent00 As ADODB.Recordset Dim StuCoursesInfo As ADODB.Recordset Dim MajorInfo As ADODB.Recordset Dim msgstr As String PrStuHier.vbp - version with internal code Dim the connection and the recordsets. Private Sub Form_Load() Dim DBPath As String DBPath = App.Path If Right(DBPath, 1) <> "\" Then DBPath = DBPath & "\" End If DBPath = DBPath & "studentrel00.mdb" Set comStuHier = New ADODB.Connection 'Difference in connection string provider because using the shape language 'Provider is MSDataShape and there is a Data Provider which is the Microsoft.Jet.OLEDB.4.0 With comStuHier.ConnectionString = "Provider = MSDataShape;" & _ "Data Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Persist Security Info=False;" & _ "Data Source=" & DBPath.Open End With 'Set...new loads object into memory Set the connection associated with the Dim statement above.
5
'Set...new loads object into memory Set rsStudent00 = New ADODB.Recordset Dim SQLCmd As String 'Note the use of { which is a brace with Shape and the use of ({ which is parenthesis brace ' 'Appending a field for each select to each row of the primary recordset which is Student00 'Each appended field is a reference to the matching records in the secondary tables SQLCmd = "SHAPE {SELECT * FROM student00} AS Student00 " & _ "APPEND ({SELECT * FROM major00} AS Major00 " & _ "RELATE 'majorcode' TO 'majorcode') AS Major00, " & _ "({SELECT * FROM stucourse00} AS StuCourses00 " & _ "RELATE 'studentidno' TO 'studentidno') AS StuCourses00" 'Note the SQLCmd is a shape language statement that creates a single hierarchical data set 'from the 3 tables referenced in the shape command With rsStudent00.CursorLocation = adUseClient.CursorType = adOpenDynamic.LockType = adLockOptimistic.Open SQLCmd, comStuHier,,, adCmdText End With Continue Form_Load This code deals with the rsStudent00 recordset.
6
From version of PrStuHier.vbp that was done using the data environment.
7
Continue Form_Load 'This gets the entire row from the major00 table Set MajorInfo = rsStudent00.Fields("Major00").Value Set StuCoursesInfo = rsStudent00.Fields("StuCourses00").Value 'Binding the textboxes to the data in the recordset Set txtstudentidno.DataSource = rsStudent00 Set txtname.DataSource = rsStudent00 Set txtmajorcode.DataSource = rsStudent00 Set txtmajorname.DataSource = MajorInfo 'Deals with the data grid With dgdCourses Set.DataSource = StuCoursesInfo.Columns(0).Caption = "Stu ID #".Columns(1).Caption = "Crs Cd".Columns(2).Caption = "Semester".Columns(3).Caption = "Grade".Refresh End With 'Deals with the flex grid Set flxStuHier.DataSource = rsStudent00 End Sub Dim comStuHier As ADODB.Connection Dim rsStudent00 As ADODB.Recordset Dim StuCoursesInfo As ADODB.Recordset Dim MajorInfo As ADODB.Recordset Dim msgstr As String These are the Dim statements from the General area. MajorInfo and StuCourseInfo are getting information from the hierarchy that was created using the Shape language. For example, note that in the Set MajorInfo you use Major00 which comes from rsStudent00. This code establishes the data grid as having StuCoursesInfo as its data source. The captions are also added to the grid. The majorname is gotten from MajorInfo so the set statement establishes it as the data source. The data source for the flex grid is the rsStudent00 hierarchy that was created.
8
'Binding the textboxes to the data in the recordset Set txtstudentidno.DataSource = rsStudent00 txtstudentidno.DataField = "studentidno" 'The DataField is set in the properties - if it wasn't, I could use the code above. Alternate code:
9
Set txtmajorname.DataSource = MajorInfo 'txtmajorname.DataField = "majorname" 'Another example of the alternative of putting it into the code. Alternate code:
10
Private Sub cmdFirst_Click() rsStudent00.MoveFirst End Sub Private Sub cmdLast_Click() rsStudent00.MoveLast End Sub Private Sub cmdNext_Click() rsStudent00.MoveNext If rsStudent00.EOF Then rsStudent00.MoveLast End If End Sub Private Sub cmdPrevious_Click() rsStudent00.MovePrevious If rsStudent00.BOF Then rsStudent00.MoveFirst End If End Sub Navigation code
11
'Deals with the data grid With dgdCourses Set.DataSource = StuCoursesInfo.Columns(0).Caption = "Stu ID #".Columns(1).Caption = "Crs Cd".Columns(2).Caption = "Semester".Columns(3).Caption = "Grade".Refresh End With
12
'Appending a field for each select to each row of the primary recordset which is Student00 'Each appended field is a reference to the matching records in the secondary tables SQLCmd = "SHAPE {SELECT * FROM student00} AS Student00 " & _ "APPEND ({SELECT * FROM major00} AS Major00 " & _ "RELATE 'majorcode' TO 'majorcode') AS Major00, " & _ "({SELECT * FROM stucourse00} AS StuCourses00 " & _ "RELATE 'studentidno' TO 'studentidno') AS StuCourses00" 'Note the SQLCmd is a shape language statement that creates a single hierarchical data set 'from the 3 tables referenced in the shape command With rsStudent00.CursorLocation = adUseClient.CursorType = adOpenDynamic.LockType = adLockOptimistic.Open SQLCmd, comStuHier,,, adCmdText End With... 'Deals with the flex grid Set flxStuHier.DataSource = rsStudent00 Appears at the bottom of the Form_Load routine.
15
With flxStuHier Set.DataSource = rsStudent00.RowHeight(0) = 0.ColHeader(0) = flexColHeaderOn.ColHeaderCaption(0, 1) = "Stu ID#".ColWidth(1, 0) = 650.ColHeaderCaption(0, 2) = "Name".ColWidth(2, 0) = 1800.ColHeaderCaption(0, 3) = "City".ColHeader(1) = flexColHeaderOn.ColWidth(4, 0) = 0.ColHeaderCaption(1, 0) = "Maj Cd".ColWidth(0, 1) = 600.ColHeaderCaption(1, 1) = "Major Name".ColWidth(1, 1) = 1800.ColHeaderCaption(1, 2) = "Major Advisor".ColWidth(2, 1) = 1800.ColHeader(2) = flexColHeaderOn.ColWidth(0, 2) = 0.ColHeaderCaption(2, 1) = "Course Cd".ColHeaderCaption(2, 2) = "Sem. Taken".ColHeaderCaption(2, 3) = "Grade" End With By setting the RowHeight on the 0 row to a height of 0, I make the established headers go away. Now I turn the flexColHeaderOn for each of the three bands (band 0 through band 2) and then set the column width and caption. Note that when setting the caption, you use band, column in parenthesis and when setting the width you use column, band in parenthesis. Set the width to 0 and you will not see the column.
16
Alternate program
17
SQLCmd = "SHAPE {SELECT * FROM student00} AS Student00 " & _ "APPEND ({SELECT * FROM major00} AS Major00 " & _ "RELATE 'majorcode' TO 'majorcode') AS Major00, " & _ "({SELECT * FROM stucourse00} AS StuCourses00 " & _ "RELATE 'studentidno' TO 'studentidno') AS StuCourses00" SQLCmd = "SHAPE {SELECT studentidno, name, city, majorcode FROM student00} AS Student00 " & _ "APPEND ({SELECT majorcode, majorname, advisor FROM major00} AS Major00 " & _ "RELATE 'majorcode' TO 'majorcode') AS Major00, " & _ "({SELECT * FROM stucourse00} AS StuCourses00 " & _ "RELATE 'studentidno' TO 'studentidno') AS StuCourses00" This shows two possible SHAPE commands. One selects all of the data from student00, the other selects just specified fields from student00. That is the one that was in effect for this program. Alternate version of the program continued
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.