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 / browse.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-04-03  |  14.0 KB  |  445 lines

  1. VERSION 2.00
  2. Begin Form PrimaryWindow 
  3.    BackColor       =   &H00FFFF00&
  4.    Caption         =   "Browse Mode Example"
  5.    Height          =   5190
  6.    Icon            =   BROWSE.FRX:0000
  7.    Left            =   1515
  8.    LinkMode        =   1  'Source
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    ScaleHeight     =   4665
  12.    ScaleWidth      =   6105
  13.    Top             =   930
  14.    Width           =   6225
  15.    Begin VBSQL VBSQL1 
  16.       Caption         =   "SQL Msg/Err"
  17.       Height          =   255
  18.       Left            =   3840
  19.       Top             =   4440
  20.       Visible         =   0   'False
  21.       Width           =   1935
  22.    End
  23.    Begin TextBox Contract_Edit 
  24.       Height          =   285
  25.       Left            =   3840
  26.       TabIndex        =   19
  27.       Top             =   4200
  28.       Width           =   1935
  29.    End
  30.    Begin CommandButton Command3 
  31.       Caption         =   "Exit"
  32.       Height          =   495
  33.       Left            =   1200
  34.       TabIndex        =   1
  35.       Top             =   3960
  36.       Width           =   855
  37.    End
  38.    Begin CommandButton Command1 
  39.       Caption         =   "About"
  40.       Height          =   495
  41.       Left            =   240
  42.       TabIndex        =   13
  43.       Top             =   3960
  44.       Width           =   855
  45.    End
  46.    Begin TextBox Zip_Code_Edit 
  47.       Height          =   285
  48.       Left            =   3840
  49.       TabIndex        =   18
  50.       Top             =   3720
  51.       Width           =   1935
  52.    End
  53.    Begin TextBox State_Edit 
  54.       Height          =   285
  55.       Left            =   3840
  56.       TabIndex        =   17
  57.       Top             =   3240
  58.       Width           =   1935
  59.    End
  60.    Begin CommandButton Cancel_Query_Button 
  61.       Caption         =   "Cancel Query"
  62.       Height          =   615
  63.       Left            =   240
  64.       TabIndex        =   8
  65.       Top             =   3000
  66.       Width           =   1815
  67.    End
  68.    Begin TextBox City_Edit 
  69.       Height          =   285
  70.       Left            =   3840
  71.       TabIndex        =   20
  72.       Top             =   2760
  73.       Width           =   1935
  74.    End
  75.    Begin TextBox Address_Edit 
  76.       Height          =   285
  77.       Left            =   3840
  78.       TabIndex        =   16
  79.       Top             =   2280
  80.       Width           =   1935
  81.    End
  82.    Begin CommandButton Update_Button 
  83.       Caption         =   "Update Row"
  84.       Height          =   615
  85.       Left            =   240
  86.       TabIndex        =   11
  87.       Top             =   2040
  88.       Width           =   1815
  89.    End
  90.    Begin TextBox Phone_Edit 
  91.       Height          =   285
  92.       Left            =   3840
  93.       TabIndex        =   15
  94.       Top             =   1800
  95.       Width           =   1935
  96.    End
  97.    Begin TextBox First_Name_Edit 
  98.       Height          =   285
  99.       Left            =   3840
  100.       TabIndex        =   14
  101.       Top             =   1320
  102.       Width           =   1935
  103.    End
  104.    Begin CommandButton Next_Button 
  105.       Caption         =   "Next Row"
  106.       Height          =   615
  107.       Left            =   240
  108.       TabIndex        =   12
  109.       Top             =   1200
  110.       Width           =   1815
  111.    End
  112.    Begin TextBox Last_Name_Edit 
  113.       Height          =   285
  114.       Left            =   3840
  115.       TabIndex        =   22
  116.       Top             =   840
  117.       Width           =   1935
  118.    End
  119.    Begin CommandButton Select_Button 
  120.       Caption         =   "Select for Browse"
  121.       Height          =   615
  122.       Left            =   240
  123.       TabIndex        =   0
  124.       Top             =   360
  125.       Width           =   1815
  126.    End
  127.    Begin Label Label9 
  128.       BackColor       =   &H00FFFF00&
  129.       Caption         =   "Contract:"
  130.       Height          =   255
  131.       Left            =   2640
  132.       TabIndex        =   10
  133.       Top             =   4200
  134.       Width           =   825
  135.    End
  136.    Begin Label Label6 
  137.       BackColor       =   &H00FFFF00&
  138.       Caption         =   "Zip Code:"
  139.       Height          =   255
  140.       Left            =   2640
  141.       TabIndex        =   6
  142.       Top             =   3720
  143.       Width           =   975
  144.    End
  145.    Begin Label Label5 
  146.       BackColor       =   &H00FFFF00&
  147.       Caption         =   "State:"
  148.       Height          =   255
  149.       Left            =   2640
  150.       TabIndex        =   5
  151.       Top             =   3240
  152.       Width           =   555
  153.    End
  154.    Begin Label Label4 
  155.       BackColor       =   &H00FFFF00&
  156.       Caption         =   "City:"
  157.       Height          =   285
  158.       Left            =   2640
  159.       TabIndex        =   4
  160.       Top             =   2760
  161.       Width           =   420
  162.    End
  163.    Begin Label Label8 
  164.       BackColor       =   &H00FFFF00&
  165.       Caption         =   "Address:"
  166.       Height          =   255
  167.       Left            =   2640
  168.       TabIndex        =   9
  169.       Top             =   2280
  170.       Width           =   780
  171.    End
  172.    Begin Label Label3 
  173.       BackColor       =   &H00FFFF00&
  174.       Caption         =   "Phone:"
  175.       Height          =   255
  176.       Left            =   2640
  177.       TabIndex        =   3
  178.       Top             =   1800
  179.       Width           =   630
  180.    End
  181.    Begin Label Label7 
  182.       BackColor       =   &H00FFFF00&
  183.       Caption         =   "First Name:"
  184.       Height          =   255
  185.       Left            =   2655
  186.       TabIndex        =   23
  187.       Top             =   1365
  188.       Width           =   1095
  189.    End
  190.    Begin Label Label2 
  191.       BackColor       =   &H00FFFF00&
  192.       Caption         =   "Last Name:"
  193.       Height          =   255
  194.       Left            =   2670
  195.       TabIndex        =   7
  196.       Top             =   870
  197.       Width           =   1095
  198.    End
  199.    Begin Label Author_ID_Label 
  200.       BackColor       =   &H00FFFF00&
  201.       Height          =   255
  202.       Left            =   3840
  203.       TabIndex        =   21
  204.       Top             =   405
  205.       Width           =   1935
  206.    End
  207.    Begin Label Label1 
  208.       BackColor       =   &H00FFFF00&
  209.       Caption         =   "Author ID:"
  210.       Height          =   195
  211.       Left            =   2640
  212.       TabIndex        =   2
  213.       Top             =   360
  214.       Width           =   915
  215.    End
  216. Dim Qual$
  217. Dim UpdateValueArray(8) As String
  218. Dim TableNameArray(8) As String
  219. Sub Address_Edit_Change ()
  220.     If Address_Edit.Text <> "not changed" Then
  221.         Update_Button.Enabled = True
  222.         UpdateValueArray(3) = Address_Edit.Text
  223.     End If
  224. End Sub
  225. Sub Cancel_Query_Button_Click ()
  226.     Rem Cancel Query
  227.     PrimaryWindow.MousePointer = 11
  228.     Results% = SQLCanQuery(SqlConn%)
  229.     ClearAuthorInformation
  230.     Select_Button.Enabled = True
  231.     Cancel_Query_Button.Enabled = False
  232.     Update_Button.Enabled = False
  233.     Next_Button.Enabled = False
  234.     PrimaryWindow.MousePointer = 0
  235. End Sub
  236. Sub CheckForTimestampColumn ()
  237.     Rem Change context to pubs sample database
  238.     Results% = SqlUse(SqlConn%, "pubs")
  239.     Results% = SqlUse(SqlUpdConn%, "pubs")
  240.     If Results% = FAIL Then
  241.         Beep
  242.         Msg$ = "The SQL Server you have logged" + Chr$(13) + Chr$(10)
  243.         Msg$ = Msg$ + "into (" + Servername$ + ") does not contain the" + Chr$(13) + Chr$(10)
  244.         Msg$ = Msg$ + "Pubs sample database."
  245.         MsgBox Msg$
  246.         ExitApplication
  247.     Else
  248.         Rem Check to see if sample authors table has a timestamp column
  249.         Cmd$ = "If 'timestamp' in (select c.name from syscolumns c, "
  250.         Cmd$ = Cmd$ + "sysobjects o where c.id = o.id and o.name = 'authors') "
  251.         Cmd$ = Cmd$ + "select -1 else select 0 "
  252.         Results% = ExecuteSQLCommand(Cmd$)
  253.         Do While (SqlResults%(SqlConn%) <> NOMORERESULTS)
  254.             Do While (SqlNextRow(SqlConn%) <> NOMOREROWS)
  255.                 Timestamp_Found% = Val(Sqldata(SqlConn%, 1))
  256.             Loop
  257.         Loop
  258.         If Not Timestamp_Found% Then
  259.             Rem Add timestamp column
  260.             Cmd$ = "alter table authors add timestamp timestamp null "
  261.             Results% = ExecuteSQLCommand(Cmd$)
  262.             Do While (SqlResults%(SqlConn%) <> NOMORERESULTS)
  263.                 Do While (SqlNextRow(SqlConn%) <> NOMOREROWS)
  264.                 Loop
  265.             Loop
  266.             Rem Now initialize the timestamp values
  267.             Cmd$ = "update authors set au_id = au_id"
  268.             Results% = ExecuteSQLCommand(Cmd$)
  269.             Do While (SqlResults%(SqlConn%) <> NOMORERESULTS)
  270.                 Do While (SqlNextRow(SqlConn%) <> NOMOREROWS)
  271.                 Loop
  272.             Loop
  273.         End If
  274.     End If
  275. End Sub
  276. Sub City_Edit_Change ()
  277.     If City_Edit.Text <> "not changed" Then
  278.         Update_Button.Enabled = True
  279.         UpdateValueArray(4) = City_Edit.Text
  280.     End If
  281. End Sub
  282. Sub ClearAuthorInformation ()
  283.     Author_ID_Label.Caption = ""
  284.     First_Name_Edit.Text = ""
  285.     Last_Name_Edit.Text = ""
  286.     Phone_Edit.Text = ""
  287.     Address_Edit.Text = ""
  288.     City_Edit.Text = ""
  289.     State_Edit.Text = ""
  290.     Zip_Code_Edit.Text = ""
  291.     Contract_Edit.Text = ""
  292. End Sub
  293. Sub Command1_Click ()
  294.     About_Form.Show 1
  295. End Sub
  296. Sub Command3_Click ()
  297.     ExitApplication
  298. End Sub
  299. Sub Contract_Edit_Change ()
  300.     If Contract_Edit.Text <> "not changed" Then
  301.         Update_Button.Enabled = True
  302.         UpdateValueArray(7) = Contract_Edit.Text
  303.     End If
  304. End Sub
  305. Sub First_Name_Edit_Change ()
  306.     If First_Name_Edit.Text <> "not changed" Then
  307.         Update_Button.Enabled = True
  308.         UpdateValueArray(1) = First_Name_Edit.Text
  309.     End If
  310. End Sub
  311. Sub Form_Load ()
  312.         
  313.     LoadTableNameArray
  314.     PrimaryWindowTitle$ = "Browse Mode Example"
  315.     InitializeApplication
  316.     Login.Show 1
  317.     CheckForTimestampColumn
  318.     DatabaseName = SqlName(SqlConn%)
  319.     ChangePrimaryWindowCaption
  320.     Cancel_Query_Button.Enabled = False
  321.     Next_Button.Enabled = False
  322.     Update_Button.Enabled = False
  323. End Sub
  324. Sub Form_Unload (Cancel As Integer)
  325.     ExitApplication
  326. End Sub
  327. Sub InitializeUpdateArray ()
  328.     Dim count As Integer
  329.     For count = 0 To 7
  330.         UpdateValueArray(count) = "not changed"
  331.     Next
  332. End Sub
  333. Sub Last_Name_Edit_Change ()
  334.     If Last_Name_Edit.Text <> "not changed" Then
  335.         Update_Button.Enabled = True
  336.         UpdateValueArray(0) = Last_Name_Edit.Text
  337.     End If
  338. End Sub
  339. Sub LoadTableNameArray ()
  340.     TableNameArray(0) = "au_lname"
  341.     TableNameArray(1) = "au_fname"
  342.     TableNameArray(2) = "phone"
  343.     TableNameArray(3) = "address"
  344.     TableNameArray(4) = "city"
  345.     TableNameArray(5) = "state"
  346.     TableNameArray(6) = "zip"
  347.     TableNameArray(7) = "contract"
  348. End Sub
  349. Sub Next_Button_Click ()
  350.     PrimaryWindow.MousePointer = 11
  351.     If SqlNextRow%(SqlConn%) <> NOMOREROWS Then
  352.         ProcessResultRow
  353.     Else
  354.         Next_Button.Enabled = False
  355.         Cancel_Query_Button.Enabled = False
  356.         Select_Button.Enabled = True
  357.         ClearAuthorInformation
  358.         Beep
  359.         MsgBox "No more rows in table."
  360.     End If
  361.     InitializeUpdateArray
  362.     Update_Button.Enabled = False
  363.     PrimaryWindow.MousePointer = 0
  364. End Sub
  365. Sub Phone_Edit_Change ()
  366.     If Phone_Edit.Text <> "not changed" Then
  367.         Update_Button.Enabled = True
  368.         UpdateValueArray(2) = Phone_Edit.Text
  369.     End If
  370. End Sub
  371. Sub ProcessResultRow ()
  372.     Author_ID_Label.Caption = Sqldata(SqlConn%, 1)
  373.     Last_Name_Edit.Text = Sqldata(SqlConn%, 2)
  374.     First_Name_Edit.Text = Sqldata(SqlConn%, 3)
  375.     Phone_Edit.Text = Sqldata(SqlConn%, 4)
  376.     Address_Edit.Text = Sqldata(SqlConn%, 5)
  377.     City_Edit.Text = Sqldata(SqlConn%, 6)
  378.     State_Edit.Text = Sqldata(SqlConn%, 7)
  379.     Zip_Code_Edit.Text = Sqldata(SqlConn%, 8)
  380.     Contract_Edit.Text = Sqldata(SqlConn%, 9)
  381.     Rem Get Qual String
  382.     Qual$ = SqlQual$(SqlConn%, -1, "authors")
  383. End Sub
  384. Sub Select_Button_Click ()
  385.     Rem Send Query to SQL Server
  386.     PrimaryWindow.MousePointer = 11
  387.     Results% = ExecuteSQLCommand("Select * from authors for browse")
  388.     Results% = SqlResults%(SqlConn%)
  389.     If SqlNextRow%(SqlConn%) <> NOMOREROWS Then
  390.         ProcessResultRow
  391.     End If
  392.     Cancel_Query_Button.Enabled = True
  393.     Next_Button.Enabled = True
  394.     Update_Button.Enabled = False
  395.     Select_Button.Enabled = False
  396.     InitializeUpdateArray
  397.     PrimaryWindow.MousePointer = 0
  398.         
  399. End Sub
  400. Sub State_Edit_Change ()
  401.     If State_Edit.Text <> "not changed" Then
  402.         Update_Button.Enabled = True
  403.         UpdateValueArray(5) = State_Edit.Text
  404.     End If
  405. End Sub
  406. Sub Update_Button_Click ()
  407.     Dim count As Integer
  408.     PrimaryWindow.MousePointer = 11
  409.     Cmd$ = "update authors set "
  410.     For count = 0 To 7
  411.         If UpdateValueArray(count) <> "not changed" Then
  412.             Cmd$ = Cmd$ + TableNameArray(count) + " = '"
  413.             Cmd$ = Cmd$ + UpdateValueArray(count) + "',"
  414.         End If
  415.     Next
  416.     Rem Replace final comma with space before adding qual string
  417.     Cmd$ = Left$(Cmd$, Len(Cmd$) - 1) + " "
  418.     Rem Now add qual string
  419.     Cmd$ = Cmd$ + Qual$
  420.     Results% = SqlCmd(SqlUpdConn%, Cmd$)
  421.     Results% = SqlExec(SqlUpdConn%)
  422.     Do While (SqlResults%(SqlUpdConn%) <> NOMORERESULTS)
  423.         Do While (SqlNextRow(SqlUpdConn%) <> NOMOREROWS)
  424.         Loop
  425.     Loop
  426.     Update_Button.Enabled = False
  427.     PrimaryWindow.MousePointer = 0
  428. End Sub
  429. Sub VBSQL1_Error (SqlConn As Integer, Severity As Integer, ErrorNum As Integer, ErrorStr As String, RetCode As Integer)
  430. ' Call the required VBSQL error-handling function
  431. ' OSErr and OSErrStr not used in VBSQL for Windows, but DOS interprets
  432. ' anything other than -1 as an OS error
  433.     OsErr% = -1
  434.     RetCode% = UserSqlErrorHandler%(SqlConn, Severity%, ErrorNum%, OsErr%, ErrorStr$, OsErrStr$)
  435. End Sub
  436. Sub VBSQL1_Message (SqlConn As Integer, Message As Long, State As Integer, Severity As Integer, MsgStr As String)
  437.     UserSqlMsgHandler SqlConn, Message&, State%, Severity%, MsgStr$
  438. End Sub
  439. Sub Zip_Code_Edit_Change ()
  440.     If Zip_Code_Edit.Text <> "not changed" Then
  441.         Update_Button.Enabled = True
  442.         UpdateValueArray(6) = Zip_Code_Edit.Text
  443.     End If
  444. End Sub
  445.