pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin private pastebin - collaborative debugging tool What's a private pastebin?

Posted by Ex on Mon 30th Aug 23:47
download | new post

  1. Imports ADODB
  2. Imports ADOX
  3.  
  4. Public Class frmDatabaseMetaDataExamples
  5.     Dim con As New ADODB.Connection
  6.  
  7.     Dim cat As New ADOX.Catalog
  8.     Dim tbl As New ADOX.Table
  9.     Dim col As ADOX.Column
  10.     Dim vw As ADOX.View
  11.     Dim ky As ADOX.Key
  12.     Dim idx As New ADOX.Index
  13.  
  14.  
  15.     Private Sub frmDatabaseMetaDataExamples_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  16.  
  17.         Dim strDatabaseLocation As String
  18.  
  19.         strDatabaseLocation = Application.StartupPath
  20.         con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " & strDatabaseLocation & "\EmployeeDepartment.mdb"
  21.         'An alternate to the database detailed above is given below. Both are provided.
  22.         'con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = " & strDatabaseLocation & "\newResults.mdb"
  23.     End Sub
  24.  
  25.     Private Sub btnClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click, _
  26.                                                                                                                                        btn12.Click
  27.         Dim btn As New Button
  28.         btn = DirectCast(sender, Button)
  29.  
  30.         rtb.Text = ""
  31.  
  32.         con.Open()
  33.         cat.ActiveConnection = con
  34.  
  35.         Select Case btn.Name
  36.             Case "btn1"
  37.                 For Each Me.tbl In cat.Tables
  38.                     rtb.Text = rtb.Text & tbl.Name & ControlChars.NewLine
  39.                 Next
  40.  
  41.             Case "btn2"
  42.                 For Each Me.tbl In cat.Tables
  43.                     If tbl.Type = "TABLE" Then
  44.                         rtb.Text = rtb.Text & tbl.Name & ControlChars.NewLine
  45.                     End If
  46.                 Next
  47.  
  48.             Case "btn3"
  49.                 For Each Me.tbl In cat.Tables
  50.                     rtb.Text = rtb.Text & tbl.Name & " - " & tbl.Columns.Count & IIf(tbl.Columns.Count = 1, " field.", " fields.") & ControlChars.NewLine
  51.                 Next
  52.  
  53.             Case "btn4"
  54.                 For Each Me.tbl In cat.Tables
  55.                     If tbl.Type = "TABLE" Then
  56.                         rtb.Text = rtb.Text & tbl.Name & " - " & tbl.Columns.Count & IIf(tbl.Columns.Count = 1, " field.", " fields.") & ControlChars.NewLine
  57.                     End If
  58.                 Next
  59.  
  60.             Case "btn5"
  61.                 For Each Me.tbl In cat.Tables
  62.                     rtb.Text = rtb.Text & "Table: " & tbl.Name & " - " & tbl.Columns.Count & IIf(tbl.Columns.Count = 1, " field.", " fields.") & ControlChars.NewLine
  63.  
  64.                     For Each Me.col In tbl.Columns
  65.                         rtb.Text = rtb.Text & "      Field: " & col.Name & ControlChars.NewLine
  66.                     Next
  67.  
  68.                     rtb.Text = rtb.Text & ControlChars.NewLine
  69.                 Next
  70.  
  71.             Case "btn6"
  72.                 For Each Me.tbl In cat.Tables
  73.                     If tbl.Type = "TABLE" Then
  74.                         rtb.Text = rtb.Text & "Table: " & tbl.Name & " - " & tbl.Columns.Count & IIf(tbl.Columns.Count = 1, " field.", " fields.") & ControlChars.NewLine
  75.  
  76.                         For Each Me.col In tbl.Columns
  77.                             rtb.Text = rtb.Text & "      Field: " & col.Name & ControlChars.NewLine
  78.                         Next
  79.  
  80.                         rtb.Text = rtb.Text & ControlChars.NewLine
  81.                     End If
  82.                 Next
  83.  
  84.             Case "btn7"
  85.                 For Each Me.tbl In cat.Tables
  86.                     If tbl.Type = "TABLE" Then
  87.                         rtb.Text = rtb.Text & tbl.Name & ControlChars.NewLine
  88.  
  89.                         For Each Me.col In tbl.Columns
  90.                             rtb.Text = rtb.Text & "      " & col.Name & ControlChars.NewLine
  91.                         Next
  92.  
  93.                         rtb.Text = rtb.Text & ControlChars.NewLine
  94.                     End If
  95.                 Next
  96.  
  97.             Case "btn8"
  98.                 For Each Me.tbl In cat.Tables
  99.                     If tbl.Type = "VIEW" Then
  100.                         rtb.Text = rtb.Text & tbl.Name & ControlChars.NewLine
  101.                     End If
  102.                 Next
  103.  
  104.             Case "btn9"
  105.                 For Each vw As ADOX.View In cat.Views
  106.                     rtb.Text = rtb.Text & vw.Name & ControlChars.NewLine & ControlChars.NewLine & vw.Command.CommandText & ControlChars.NewLine
  107.                 Next
  108.  
  109.             Case "btn10"
  110.                 For Each Me.tbl In cat.Tables
  111.                     If tbl.Type = "TABLE" Then
  112.                         rtb.Text = rtb.Text & "The " & tbl.Name & " table" & ControlChars.NewLine & ControlChars.NewLine
  113.  
  114.                         For Each Me.idx In tbl.Indexes
  115.                             If idx.PrimaryKey = True Then
  116.                                 rtb.Text = rtb.Text & "Primary key: " & ControlChars.NewLine & "      "
  117.  
  118.                                 Dim i As Integer
  119.  
  120.                                 For i = 0 To idx.Columns.Count - 1
  121.                                     rtb.Text = rtb.Text & idx.Columns(i).Name & ", "
  122.                                 Next
  123.                             End If
  124.                         Next
  125.  
  126.                         rtb.Text = rtb.Text.Substring(0, rtb.Text.Length - 2)
  127.                         rtb.Text = rtb.Text & ControlChars.NewLine & ControlChars.NewLine
  128.                         rtb.Text = rtb.Text & "=================================================" & ControlChars.NewLine
  129.                     End If
  130.                 Next
  131.  
  132.             Case "btn11"
  133.                 For Each Me.tbl In cat.Tables
  134.                     If tbl.Type = "TABLE" Then
  135.                         rtb.Text = rtb.Text & "The " & tbl.Name & " table" & ControlChars.NewLine & ControlChars.NewLine
  136.  
  137.                         For Each Me.idx In tbl.Indexes
  138.                             If idx.PrimaryKey = True Then
  139.                                 rtb.Text = rtb.Text & "Primary key: " & ControlChars.NewLine & "      "
  140.  
  141.                                 Dim i As Integer
  142.  
  143.                                 For i = 0 To idx.Columns.Count - 1
  144.                                     rtb.Text = rtb.Text & idx.Columns(i).Name & ", "
  145.                                 Next
  146.                             End If
  147.                         Next
  148.  
  149.                         rtb.Text = rtb.Text.Substring(0, rtb.Text.Length - 2)
  150.                         rtb.Text = rtb.Text & ControlChars.NewLine & ControlChars.NewLine
  151.  
  152.                         For Each Me.ky In Me.tbl.Keys
  153.                             If (ky.Type = ADOX.KeyTypeEnum.adKeyForeign) Then
  154.                                 rtb.Text = rtb.Text & "The " & tbl.Name & " table is related to the " & ky.RelatedTable & " table by the " & ky.Name & " relationship." & ControlChars.NewLine & ControlChars.NewLine
  155.                                 rtb.Text = rtb.Text & "Properties of the " & ky.Name & " relationship: " & ControlChars.NewLine & "      Table: " & tbl.Name & ControlChars.NewLine & "      Foreign Table: " & ky.RelatedTable & ControlChars.NewLine & ControlChars.NewLine
  156.                             End If
  157.                         Next
  158.  
  159.                         rtb.Text = rtb.Text & "=================================================" & ControlChars.NewLine
  160.                     End If
  161.                 Next
  162.  
  163.             Case "btn12"
  164.                 For Each Me.tbl In cat.Tables
  165.                     If tbl.Type = "TABLE" Then
  166.                         rtb.Text = rtb.Text & "The " & tbl.Name & " table" & ControlChars.NewLine & ControlChars.NewLine
  167.  
  168.                         For Each Me.idx In tbl.Indexes
  169.                             If idx.PrimaryKey = True Then
  170.                                 rtb.Text = rtb.Text & "Primary key: " & ControlChars.NewLine & "      "
  171.  
  172.                                 Dim i As Integer
  173.  
  174.                                 For i = 0 To idx.Columns.Count - 1
  175.                                     rtb.Text = rtb.Text & idx.Columns(i).Name & ", "
  176.                                 Next
  177.                             End If
  178.                         Next
  179.  
  180.                         rtb.Text = rtb.Text.Substring(0, rtb.Text.Length - 2)
  181.                         rtb.Text = rtb.Text & ControlChars.NewLine & ControlChars.NewLine
  182.  
  183.                         For Each Me.ky In tbl.Keys
  184.                             If (ky.Type = ADOX.KeyTypeEnum.adKeyForeign) Then
  185.                                 For Each Me.col In ky.Columns
  186.                                     rtb.Text = rtb.Text & "Foreign key: " & ControlChars.NewLine & "      "
  187.                                     rtb.Text = rtb.Text & col.Name & ControlChars.NewLine & "(which links to a primary key attribute called " & col.RelatedColumn & " in the " & ky.RelatedTable & " table, via the " & ky.Name & " relationship)" & ControlChars.NewLine & ControlChars.NewLine
  188.                                 Next
  189.  
  190.                                 rtb.Text = rtb.Text & "Properties of the " & ky.Name & " relationship: " & ControlChars.NewLine & "      Table: " & tbl.Name & ControlChars.NewLine & "      Related Table: " & ky.RelatedTable & ControlChars.NewLine & ControlChars.NewLine
  191.                             End If
  192.                         Next
  193.  
  194.                         rtb.Text = rtb.Text & "=================================================" & ControlChars.NewLine
  195.                     End If
  196.                 Next
  197.         End Select
  198.  
  199.         con.Close()
  200.  
  201.     End Sub
  202.  
  203.     Private Sub btnClearText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearText.Click
  204.         rtb.Text = ""
  205.     End Sub
  206.  
  207.     Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
  208.         End
  209.     End Sub
  210. End Class

Submit a correction or amendment below. (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Use syntax highlighting

To highlight particular lines, prefix each line with @@


Remember my settings