Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Data.SqlClient
Public Class Form1
Private mycon As SqlConnection
Private conStr As String = "Data Source=web\sqlExpress;Initial Catalog=dtEmployee;User ID=sa;Password=matco1234"
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click
InitialEmployee()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
mycon = New SqlConnection(conStr)
If mycon.State = ConnectionState.Closed Then
mycon.Open()
End If
' Catch ex As Exception
' MsgBox("Invalid connectionString")
' End Try
Catch exsql As SqlException
MsgBox(exsql.Message, MsgBoxStyle.Exclamation)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
End Sub
Sub InitialEmployee()
Dim cmd As New SqlCommand
Dim da As New SqlDataAdapter
Dim ds As New DataSet
Try
With cmd
.Connection = mycon
.CommandType = CommandType.Text
.CommandText = "select * from dtEmployee "
End With
da.SelectCommand = cmd
da.Fill(ds, "showEmployee") 'Keep data to Dataset
dgName.DataSource = ds.Tables("showEmployee")
Catch exsql As SqlException
MsgBox(exsql.Message, MsgBoxStyle.Exclamation)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
End Sub
End Class