1
Imports System.Data.OleDb Imports System.Windows.Forms Imports System.Data Public Class mdb_sql ' ************************************************************** ' フォームがロードされた時の初期処理 ' ************************************************************** Private Sub mdb_sql_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load ' フォームにグリッドをフィトさせる ' Me.LboxGrid.ParentFit(Me) ' フォームの初期位置は、StartPosition をプロパティウインドウで設定 ' ドラッグ・ドロップを許可する Me.LboxGrid.AllowDrop = True End Sub ' ************************************************************** ' フォームのサイズ変更 ' ************************************************************** Private Sub mdb_sql_SizeChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.SizeChanged ' フォームにグリッドをフィトさせる ' Me.LboxGrid.ParentFit(Me) End Sub ' ************************************************************** ' MDB をドラッグ・ドロップ ' ************************************************************** Private Sub LboxGrid_DragDrop(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.DragEventArgs) Handles LboxGrid.DragDrop ' ファイルのパスを(複数)取得 Dim target As String() = CType(e.Data.GetData(DataFormats.FileDrop, False), String()) ' 複数選択されていても、先頭のファイル Me.LboxGrid.DbServer = target(0) ' *********************************** ' 以下、テーブル一覧の取得( ADO 仕様 ) ' *********************************** Me.LboxGrid.Reset() Me.LboxGrid.AddColumn("TABLE", "表名") ' 接続文字列 Dim ConnectString As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=" & Me.LboxGrid.DbServer & ";" ' 接続オブジェクト Dim myCon As New OleDbConnection() myCon.ConnectionString = ConnectString Try myCon.Open() Catch ex As Exception MessageBox.Show(ex.Message) Exit Sub End Try Dim schemaTable As DataTable = _ myCon.GetOleDbSchemaTable( _ OleDbSchemaGuid.Tables, _ New Object() {Nothing, Nothing, Nothing, "TABLE"} _ ) myCon.Close() Dim rows As Integer = schemaTable.Rows.Count Dim i As Integer = 0 For i = 0 To rows - 1 Me.LboxGrid.AddRow() Me.LboxGrid.SetColumnText("TABLE", schemaTable.Rows(i)("TABLE_NAME").ToString()) Next End Sub ' ************************************************************** ' ドラッグ・ドロップ効果に必要な処理 ' ************************************************************** Private Sub LboxGrid_DragEnter(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.DragEventArgs) Handles LboxGrid.DragEnter ' ファイルのパスを(複数)取得 Dim target As String() = CType(e.Data.GetData(DataFormats.FileDrop, False), String()) ' 拡張子を分解 Dim ext As String = System.IO.Path.GetExtension(target(0)) ext = ext.ToUpper() ' 拡張子が MDB で無ければ許可しない If ext = ".MDB" Then e.Effect = DragDropEffects.Move Else e.Effect = DragDropEffects.None End If End Sub ' ************************************************************** ' SQL 実行 ' ************************************************************** Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click If Not Me.LboxGrid.LoadSqlMdb(Me.SqlText.Text) Then MessageBox.Show(Me.LboxGrid.DbError) End If End Sub End Class
1
?
_ Partial Class mdb_sql Inherits System.Windows.Forms.Form 'フォームがコンポーネントの一覧をクリーンアップするために dispose をオーバーライドします。
_ Protected Overrides Sub Dispose(ByVal disposing As Boolean) If disposing AndAlso components IsNot Nothing Then components.Dispose() End If MyBase.Dispose(disposing) End Sub 'Windows フォーム デザイナで必要です。 Private components As System.ComponentModel.IContainer 'メモ: 以下のプロシージャは Windows フォーム デザイナで必要です。 'Windows フォーム デザイナを使用して変更できます。 'コード エディタを使って変更しないでください。
_ Private Sub InitializeComponent() Me.LboxGrid = New lightbox.LboxGrid Me.SqlText = New System.Windows.Forms.TextBox Me.MenuStrip1 = New System.Windows.Forms.MenuStrip Me.ToolStripMenuItem1 = New System.Windows.Forms.ToolStripMenuItem Me.上部パネル = New System.Windows.Forms.Panel Me.Splitter1 = New System.Windows.Forms.Splitter Me.下部パネル = New System.Windows.Forms.Panel CType(Me.LboxGrid, System.ComponentModel.ISupportInitialize).BeginInit() Me.MenuStrip1.SuspendLayout() Me.上部パネル.SuspendLayout() Me.下部パネル.SuspendLayout() Me.SuspendLayout() ' 'LboxGrid ' Me.LboxGrid.AllowUserToAddRows = False Me.LboxGrid.AllowUserToDeleteRows = False Me.LboxGrid.AllowUserToOrderColumns = True Me.LboxGrid.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells Me.LboxGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize Me.LboxGrid.DbDatabase = Nothing Me.LboxGrid.DbDriver = Nothing Me.LboxGrid.DbPassword = Nothing Me.LboxGrid.DbServer = Nothing Me.LboxGrid.DbUser = Nothing Me.LboxGrid.Dock = System.Windows.Forms.DockStyle.Fill Me.LboxGrid.Location = New System.Drawing.Point(0, 0) Me.LboxGrid.MultiSelect = False Me.LboxGrid.Name = "LboxGrid" Me.LboxGrid.ReadOnly = True Me.LboxGrid.RowTemplate.Height = 21 Me.LboxGrid.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect Me.LboxGrid.Size = New System.Drawing.Size(768, 404) Me.LboxGrid.SizeBottom = 0 Me.LboxGrid.SizeLeft = 0 Me.LboxGrid.SizeRight = 0 Me.LboxGrid.SizeTop = 0 Me.LboxGrid.TabIndex = 3 ' 'SqlText ' Me.SqlText.Dock = System.Windows.Forms.DockStyle.Fill Me.SqlText.Location = New System.Drawing.Point(0, 0) Me.SqlText.Multiline = True Me.SqlText.Name = "SqlText" Me.SqlText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical Me.SqlText.Size = New System.Drawing.Size(768, 201) Me.SqlText.TabIndex = 1 ' 'MenuStrip1 ' Me.MenuStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.ToolStripMenuItem1}) Me.MenuStrip1.Location = New System.Drawing.Point(0, 0) Me.MenuStrip1.Name = "MenuStrip1" Me.MenuStrip1.Size = New System.Drawing.Size(768, 24) Me.MenuStrip1.TabIndex = 5 Me.MenuStrip1.Text = "MenuStrip1" ' 'ToolStripMenuItem1 ' Me.ToolStripMenuItem1.Name = "ToolStripMenuItem1" Me.ToolStripMenuItem1.Size = New System.Drawing.Size(41, 20) Me.ToolStripMenuItem1.Text = "実行" ' '上部パネル ' Me.上部パネル.Controls.Add(Me.SqlText) Me.上部パネル.Dock = System.Windows.Forms.DockStyle.Top Me.上部パネル.Location = New System.Drawing.Point(0, 24) Me.上部パネル.Name = "上部パネル" Me.上部パネル.Size = New System.Drawing.Size(768, 201) Me.上部パネル.TabIndex = 6 ' 'Splitter1 ' Me.Splitter1.Dock = System.Windows.Forms.DockStyle.Top Me.Splitter1.Location = New System.Drawing.Point(0, 225) Me.Splitter1.Name = "Splitter1" Me.Splitter1.Size = New System.Drawing.Size(768, 3) Me.Splitter1.TabIndex = 7 Me.Splitter1.TabStop = False ' '下部パネル ' Me.下部パネル.Controls.Add(Me.LboxGrid) Me.下部パネル.Dock = System.Windows.Forms.DockStyle.Fill Me.下部パネル.Location = New System.Drawing.Point(0, 228) Me.下部パネル.Name = "下部パネル" Me.下部パネル.Size = New System.Drawing.Size(768, 404) Me.下部パネル.TabIndex = 8 ' 'mdb_sql ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(768, 632) Me.Controls.Add(Me.下部パネル) Me.Controls.Add(Me.Splitter1) Me.Controls.Add(Me.上部パネル) Me.Controls.Add(Me.MenuStrip1) Me.MainMenuStrip = Me.MenuStrip1 Me.Name = "mdb_sql" Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen Me.Text = "mdb_sql" CType(Me.LboxGrid, System.ComponentModel.ISupportInitialize).EndInit() Me.MenuStrip1.ResumeLayout(False) Me.MenuStrip1.PerformLayout() Me.上部パネル.ResumeLayout(False) Me.上部パネル.PerformLayout() Me.下部パネル.ResumeLayout(False) Me.ResumeLayout(False) Me.PerformLayout() End Sub Friend WithEvents LboxGrid As lightbox.LboxGrid Friend WithEvents SqlText As System.Windows.Forms.TextBox Friend WithEvents MenuStrip1 As System.Windows.Forms.MenuStrip Friend WithEvents ToolStripMenuItem1 As System.Windows.Forms.ToolStripMenuItem Friend WithEvents 上部パネル As System.Windows.Forms.Panel Friend WithEvents Splitter1 As System.Windows.Forms.Splitter Friend WithEvents 下部パネル As System.Windows.Forms.Panel End Class