home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / sql / vbsql / vbquery.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-04-03  |  5.6 KB  |  190 lines

  1. VERSION 2.00
  2. Begin Form PrimaryWindow 
  3.    BackColor       =   &H00808000&
  4.    Caption         =   "VBSQL Sample Query Tool - [No Server]"
  5.    ForeColor       =   &H00000000&
  6.    Height          =   6120
  7.    Left            =   240
  8.    ScaleHeight     =   5430
  9.    ScaleWidth      =   8760
  10.    Top             =   660
  11.    Width           =   8880
  12.    Begin VBSQL VBSQL1 
  13.       Caption         =   "Errors"
  14.       Height          =   375
  15.       Left            =   2640
  16.       Top             =   0
  17.       Visible         =   0   'False
  18.       Width           =   1815
  19.    End
  20.    Begin CommandButton SEND_QUERY_BUTTON 
  21.       BackColor       =   &H00C0C0C0&
  22.       Caption         =   "&Send Query"
  23.       Enabled         =   0   'False
  24.       Height          =   480
  25.       Left            =   7080
  26.       TabIndex        =   5
  27.       Top             =   960
  28.       Width           =   1440
  29.    End
  30.    Begin CommandButton NEW_QUERY_BUTTON 
  31.       BackColor       =   &H00C0C0C0&
  32.       Caption         =   "&New Query"
  33.       Enabled         =   0   'False
  34.       Height          =   480
  35.       Left            =   7080
  36.       TabIndex        =   4
  37.       Top             =   240
  38.       Width           =   1440
  39.    End
  40.    Begin TextBox RESULT_FIELD 
  41.       BackColor       =   &H00FFFFFF&
  42.       FontBold        =   -1  'True
  43.       FontItalic      =   0   'False
  44.       FontName        =   "Courier"
  45.       FontSize        =   9.75
  46.       FontStrikethru  =   0   'False
  47.       FontUnderline   =   0   'False
  48.       ForeColor       =   &H00000000&
  49.       Height          =   3120
  50.       Left            =   120
  51.       MultiLine       =   -1  'True
  52.       ScrollBars      =   3  'Both
  53.       TabIndex        =   3
  54.       Top             =   1920
  55.       Width           =   8520
  56.    End
  57.    Begin TextBox QUERY_FIELD 
  58.       BackColor       =   &H00FFFFFF&
  59.       ForeColor       =   &H00000000&
  60.       Height          =   960
  61.       Left            =   120
  62.       MultiLine       =   -1  'True
  63.       ScrollBars      =   3  'Both
  64.       TabIndex        =   1
  65.       Top             =   480
  66.       Width           =   6480
  67.    End
  68.    Begin Label Label2 
  69.       BackColor       =   &H00808000&
  70.       Caption         =   "&Results:"
  71.       ForeColor       =   &H00000000&
  72.       Height          =   240
  73.       Left            =   120
  74.       TabIndex        =   2
  75.       Top             =   1680
  76.       Width           =   720
  77.    End
  78.    Begin Label Label1 
  79.       BackColor       =   &H00808000&
  80.       Caption         =   "&Query:"
  81.       ForeColor       =   &H00000000&
  82.       Height          =   240
  83.       Left            =   120
  84.       TabIndex        =   0
  85.       Top             =   240
  86.       Width           =   720
  87.    End
  88.    Begin Menu CONNECT_MENU 
  89.       Caption         =   "&Connection"
  90.       Begin Menu LOGIN_MENU 
  91.          Caption         =   "&Login"
  92.       End
  93.       Begin Menu DATABASE_MENU 
  94.          Caption         =   "Change &Database"
  95.       End
  96.       Begin Menu EXIT_MENU 
  97.          Caption         =   "E&xit"
  98.       End
  99.    End
  100.    Begin Menu HELP_MENU 
  101.       Caption         =   "&Help"
  102.       Begin Menu ABOUT_MENU 
  103.          Caption         =   "&About..."
  104.       End
  105.    End
  106. '$INCLUDE: 'VBQUERY.BI'
  107. '$INCLUDE: 'VBDSQL.BI'
  108. Sub ABOUT_MENU_Click ()
  109.     About_Form.Show 1
  110. End Sub
  111. Sub ClearFields ()
  112.     QUERY_FIELD.Text = ""
  113.     RESULT_FIELD.Text = ""
  114. End Sub
  115. Sub DATABASE_MENU_Click ()
  116.     If SqlConn = 0 Then
  117.         MsgBox "Must login first"
  118.         Exit Sub
  119.     End If
  120.     CHNGDB.Show 1
  121. End Sub
  122. Sub EXIT_MENU_Click ()
  123.     ExitApplication
  124. End Sub
  125. Sub Form_Load ()
  126. Rem Initialize the connection to SQL Server
  127.     InitializeApplication
  128.     MsgBox DBLIB_VERSION$
  129.     PrimaryWindowTitle = "VBSQL Sample Query Tool"
  130. End Sub
  131. Sub LOGIN_MENU_Click ()
  132.     Login.Show 1
  133.     NEW_QUERY_BUTTON.Enabled = -1
  134.     SEND_QUERY_BUTTON.Enabled = -1
  135. End Sub
  136. Sub NEW_QUERY_BUTTON_Click ()
  137.     ClearFields
  138.     QUERY_FIELD.SetFocus
  139. End Sub
  140. Sub SEND_QUERY_BUTTON_Click ()
  141. On Error GoTo OutofRoom
  142. Static OutputData() As String
  143. ReDim Preserve OutputData(500) As String
  144. Rem Get the query.  Make sure there is one
  145. CRLF$ = Chr$(13) + Chr$(10)
  146. cmd$ = QUERY_FIELD.Text
  147. If cmd$ = "" Then
  148.     MsgBox "There is no query in the Query field"
  149.     Exit Sub
  150. End If
  151. Rem Clear the result array, and result controls first
  152. i% = 0
  153. For i% = 0 To 499
  154.     OutputData(i%) = ""
  155. Rem Fill the result array with the data
  156. Rem Fill the results field
  157. RESULT_FIELD.Text = ""
  158. numrows& = Process_SQL_query(cmd$, OutputData())
  159. 'fill temporary string first, to avoid flashing with every row
  160. For i% = 0 To numrows& - 1
  161.     DataLine$ = DataLine$ + OutputData(i%) + CRLF$
  162. Next i%
  163. RESULT_FIELD.Text = DataLine$
  164. QUERY_FIELD.SetFocus
  165. Exit Sub
  166. OutofRoom:
  167. 'can run out of space filling strings.  If so, try just 20 rows
  168. DataLine$ = ""
  169. If numrows& > 20 Then
  170.     numrows& = 20
  171.     For i% = 0 To numrows& - 1
  172.         DataLine$ = DataLine$ + OutputData(i%) + CRLF$
  173.     Next i%
  174.     RESULT_FIELD.Text = DataLine$
  175. End If
  176. MsgBox "Out of room, output truncated"
  177. QUERY_FIELD.SetFocus
  178. Exit Sub
  179. End Sub
  180. Sub VBSQL1_Error (SqlConn As Integer, Severity As Integer, ErrorNum As Integer, ErrorStr As String, RetCode As Integer)
  181. ' Call the required VBSQL error-handling function
  182. ' OSErr and OSErrStr not used in VBSQL for Windows, but DOS interprets
  183. ' anything other than -1 as an OS error
  184.     OsErr% = -1
  185.     RetCode% = UserSqlErrorHandler%(SqlConn, Severity%, ErrorNum%, OsErr%, ErrorStr$, OsErrStr$)
  186. End Sub
  187. Sub VBSQL1_Message (SqlConn As Integer, Message As Long, State As Integer, Severity As Integer, MsgStr As String)
  188.     UserSqlMsgHandler SqlConn, Message&, State%, Severity%, MsgStr$
  189. End Sub
  190.