home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch18 / ado2 / ado2.frm (.txt) next >
Encoding:
Visual Basic Form  |  1998-07-14  |  4.6 KB  |  148 lines

  1. VERSION 5.00
  2. Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
  3. Begin VB.Form ADO2Form 
  4.    Caption         =   "ADO Examples"
  5.    ClientHeight    =   5628
  6.    ClientLeft      =   60
  7.    ClientTop       =   348
  8.    ClientWidth     =   8004
  9.    BeginProperty Font 
  10.       Name            =   "Verdana"
  11.       Size            =   9
  12.       Charset         =   0
  13.       Weight          =   400
  14.       Underline       =   0   'False
  15.       Italic          =   0   'False
  16.       Strikethrough   =   0   'False
  17.    EndProperty
  18.    LinkTopic       =   "Form1"
  19.    ScaleHeight     =   5628
  20.    ScaleWidth      =   8004
  21.    StartUpPosition =   3  'Windows Default
  22.    Begin MSFlexGridLib.MSFlexGrid Grid1 
  23.       Height          =   2772
  24.       Left            =   2604
  25.       TabIndex        =   3
  26.       Top             =   2748
  27.       Width           =   5268
  28.       _ExtentX        =   9292
  29.       _ExtentY        =   4890
  30.       _Version        =   393216
  31.       Rows            =   20
  32.       Cols            =   4
  33.       FixedCols       =   0
  34.       AllowUserResizing=   1
  35.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  36.          Name            =   "Verdana"
  37.          Size            =   9
  38.          Charset         =   0
  39.          Weight          =   400
  40.          Underline       =   0   'False
  41.          Italic          =   0   'False
  42.          Strikethrough   =   0   'False
  43.       EndProperty
  44.    End
  45.    Begin VB.CommandButton Command2 
  46.       Caption         =   "Command.Execute"
  47.       Height          =   495
  48.       Left            =   84
  49.       TabIndex        =   2
  50.       Top             =   2748
  51.       Width           =   2295
  52.    End
  53.    Begin VB.ListBox List1 
  54.       Height          =   2208
  55.       Left            =   2604
  56.       TabIndex        =   1
  57.       Top             =   108
  58.       Width           =   3228
  59.    End
  60.    Begin VB.CommandButton Command1 
  61.       Caption         =   "Connection.Execute"
  62.       Height          =   495
  63.       Left            =   84
  64.       TabIndex        =   0
  65.       Top             =   108
  66.       Width           =   2295
  67.    End
  68. Attribute VB_Name = "ADO2Form"
  69. Attribute VB_GlobalNameSpace = False
  70. Attribute VB_Creatable = False
  71. Attribute VB_PredeclaredId = True
  72. Attribute VB_Exposed = False
  73. Private Sub Command1_Click()
  74. Dim ADOconnection As New ADODB.Connection
  75. Dim RSSales As ADODB.Recordset
  76. Set ADOconnection = CreateObject("ADODB.Connection")
  77. ADOconnection.Open "DSN=NWindDB" ' "driver ={Microsoft Access Driver (*.mdb)};dbq=c:\data\intranet\intranet.mdb"
  78. Set RSSales = ADOconnection.Execute("SELECT * FROM CATEGORIES")
  79. While Not RSSales.EOF
  80.     List1.AddItem RSSales("CategoryName")
  81.     RSSales.MoveNext
  82. End Sub
  83. Private Sub Command2_Click()
  84. Dim ADOcommand As New ADODB.Command
  85. Dim ADOconnection As New ADODB.Connection
  86. Dim RSSales As New ADODB.Recordset
  87. Set ADOconnection = CreateObject("ADODB.Connection")
  88. ADOconnection.Open "DSN=NWindDB"
  89. Set ADOcommand.ActiveConnection = ADOconnection
  90. ADOcommand.Prepared = False
  91. ADOcommand.CommandText = "Invoices"
  92. ADOcommand.CommandType = adCmdStoredProc
  93. Set RSSales = ADOcommand.Execute()
  94. Grid1.Clear
  95. Grid1.ColAlignment(2) = 6
  96. Grid1.ColWidth(0) = TextWidth("9,999")
  97. Grid1.ColWidth(1) = TextWidth("A long customer's name")
  98. Grid1.ColWidth(2) = TextWidth("$999,999.99")
  99. Grid1.ColWidth(3) = TextWidth("#99/99/99#")
  100. Grid1.Row = 0
  101. Grid1.Col = 0
  102. Grid1.Text = "##"
  103. Grid1.Col = 1
  104. Grid1.Text = "Customer"
  105. Grid1.Col = 2
  106. Grid1.Text = "Inv. Total"
  107. Grid1.Col = 3
  108. Grid1.Text = "Date"
  109. Grid1.Row = 1
  110. invCounter = 1
  111. custTotal = 0
  112. Screen.MousePointer = vbHourglass
  113. While Not RSSales.EOF
  114.     invTotal = Format(RSSales("ExtendedPrice"), "$#,###.00")
  115.     custTotal = custTotal + invTotal
  116.     Grid1.Col = 0
  117.     Grid1.Text = Format(invCounter, "###")
  118.     invCounter = invCounter + 1
  119.     Grid1.Col = 1
  120.     Grid1.Text = RSSales(7)
  121.     thisCustomer = RSSales(7)
  122.     Grid1.Col = 2
  123.     Grid1.Text = invTotal
  124.     Grid1.Col = 3
  125.     Grid1.Text = RSSales(15)
  126.     If Grid1.Row = Grid1.Rows - 1 Then
  127.         Grid1.Rows = Grid1.Rows + 100
  128.     End If
  129.     Grid1.Row = Grid1.Row + 1
  130.     RSSales.MoveNext
  131.     If Not RSSales.EOF Then
  132.         If RSSales(7) <> thisCustomer Then
  133.             Grid1.Col = 1
  134.             Grid1.Text = "TOTAL"
  135.             Grid1.CellFontBold = True
  136.             Grid1.Col = 2
  137.             Grid1.Text = Format(custTotal, "$#,###.00")
  138.             Grid1.CellFontBold = True
  139.             custTotal = 0
  140.             If Grid1.Row = Grid1.Rows - 1 Then
  141.                 Grid1.Rows = Grid1.Rows + 100
  142.             End If
  143.             Grid1.Row = Grid1.Row + 1
  144.         End If
  145.     End If
  146. Screen.MousePointer = vbDefault
  147. End Sub
  148.