Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
#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)
MyBase.Dispose(disposing)
End Sub
'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
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.Button1 = New System.Windows.Forms.Button
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(72, 200)
Me.Button1.Size = New System.Drawing.Size(80, 24)
Me.Button1.Text = "Button1"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(64, 64)
Me.Label1.Text = "Label1"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(64, 96)
Me.Label2.Text = "Label2"
'
'Form1
'
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Button1)
Me.Menu = Me.MainMenu1
Me.Text = "Form1"
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connectionString As String
Dim SQL As String
Dim tmpName As String
Dim tmpCode As String
connectionString = "Server=SQLOLEDB.1; Data Source=DIEVECHNOLOGY; " & _
"Database=test; User ID=sa; Password=;"
Dim conDB As New SqlConnection(connectionString)
SQL = "Select Name, Code from Customers"
Dim comSQL As New SqlCommand(SQL, conDB)
Dim DR As SqlDataReader
Try
conDB.Open()
DR = comSQL.ExecuteReader(CommandBehavior.Default)
While DR.Read
tmpName = DR.GetString(0)
tmpCode = DR.GetValue(1)
Label1.Text = tmpName
Label2.Text = tmpCode
End While
DR.Close()
Catch ex As Exception
MessageBox.Show(Err.Description.ToString)
Finally
conDB.Close()
End Try
End Sub
End Class