GUI based SQL command executer : Database Utility « Database ADO.net « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Database ADO.net » Database UtilityScreenshots 
GUI based SQL command executer
GUI based SQL command executer

Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Data.SqlClient

public class MainClass
   Shared Sub Main()
       Dim form1 As Form = New Form1
       Application.Run(form1)
   End Sub
End Class









Public Class Form1
   Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

   Public Sub New()
      MyBase.New()

      'This call is required by the Windows Form Designer.
      InitializeComponent()

      'Add any initialization after the InitializeComponent() call

   End Sub

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
         If Not (components Is NothingThen
            components.Dispose()
         End If
      End If
      MyBase.Dispose(disposing)
   End Sub

   'Required by the Windows Form Designer
   Private components As System.ComponentModel.IContainer

   'NOTE: The following procedure is required by the Windows Form Designer
   'It can be modified using the Windows Form Designer.  
   'Do not modify it using the code editor.
   Friend WithEvents Label1 As System.Windows.Forms.Label
   Friend WithEvents Label2 As System.Windows.Forms.Label
   Friend WithEvents SqlConnection1 As System.Data.SqlClient.SqlConnection
   Friend WithEvents SqlStatement As System.Windows.Forms.TextBox
   Friend WithEvents ResultBox As System.Windows.Forms.TextBox
   Friend WithEvents ExecuteButton As System.Windows.Forms.Button
   <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
      Me.SqlStatement = New System.Windows.Forms.TextBox
      Me.ExecuteButton = New System.Windows.Forms.Button
      Me.ResultBox = New System.Windows.Forms.TextBox
      Me.Label1 = New System.Windows.Forms.Label
      Me.Label2 = New System.Windows.Forms.Label
      Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
      Me.SuspendLayout()
      '
      'SqlStatement
      '
      Me.SqlStatement.Location = New System.Drawing.Point(1632)
      Me.SqlStatement.Multiline = True
      Me.SqlStatement.Name = "SqlStatement"
      Me.SqlStatement.Size = New System.Drawing.Size(46496)
      Me.SqlStatement.TabIndex = 0
      Me.SqlStatement.Text = ""
      '
      'ExecuteButton
      '
      Me.ExecuteButton.Location = New System.Drawing.Point(211136)
      Me.ExecuteButton.Name = "ExecuteButton"
      Me.ExecuteButton.TabIndex = 1
      Me.ExecuteButton.Text = "Go"
      '
      'ResultBox
      '
      Me.ResultBox.Location = New System.Drawing.Point(16200)
      Me.ResultBox.Multiline = True
      Me.ResultBox.Name = "ResultBox"
      Me.ResultBox.Size = New System.Drawing.Size(464104)
      Me.ResultBox.TabIndex = 2
      Me.ResultBox.Text = ""
      '
      'Label1
      '
      Me.Label1.Location = New System.Drawing.Point(1048)
      Me.Label1.Name = "Label1"
      Me.Label1.Size = New System.Drawing.Size(28823)
      Me.Label1.TabIndex = 3
      Me.Label1.Text = "Type a SQL Statement below and press Go to execute it"
      '
      'Label2
      '
      Me.Label2.Location = New System.Drawing.Point(136176)
      Me.Label2.Name = "Label2"
      Me.Label2.Size = New System.Drawing.Size(22423)
      Me.Label2.TabIndex = 4
      Me.Label2.Text = "The results of your command are as follows"
      '
      'SqlConnection1
      '
      Me.SqlConnection1.ConnectionString = "server=(local)\SQLEXPRESS;" & _
          "integrated security=sspi;" & _
          "database=MyDatabase"
      'Form1
      '
      Me.AutoScaleBaseSize = New System.Drawing.Size(513)
      Me.ClientSize = New System.Drawing.Size(496317)
      Me.Controls.Add(Me.Label2)
      Me.Controls.Add(Me.Label1)
      Me.Controls.Add(Me.ResultBox)
      Me.Controls.Add(Me.ExecuteButton)
      Me.Controls.Add(Me.SqlStatement)
      Me.Name = "Form1"
      Me.Text = "Form1"
      Me.ResumeLayout(False)

   End Sub

#End Region

   Private Sub ExecuteButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles ExecuteButton.Click
      ' Get SQL Query from textbox
      Dim sql As String = SqlStatement.Text

      ' Create Command object
      Dim NewCommand As New SqlCommand(sql, SqlConnection1)

      Try
         ' Open Connection
         SqlConnection1.Open()

         ' Execute Command
         NewCommand.ExecuteNonQuery()

         ' Display Result Message
         ResultBox.Text = "SQL executed successfuly"

      Catch ex As Exception
         ' Display error message
         ResultBox.Text = ex.ToString()

      Finally
         SqlConnection1.Close()

      End Try
   End Sub
End Class

           
       
Related examples in the same category
1.Query Processor: Execute SQL command and display result in GridQuery Processor: Execute SQL command and display result in Grid
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.