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

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
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
w_w___w__.__ja__v__a_2_s___._c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.