'浏覽表數據
Private Sub btnVIEwData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnVIEwData.Click
conn = New SqlConnection(ConnectionString)
If conn.State = ConnectionState.Open Then
conn.Close()
End If
ConnectionString = "Data Source=.;Initial Catalog=MyDataBase;User Id=sa;PassWord=;"
conn.ConnectionString = ConnectionString
conn.Open()
Dim da As New SqlDataAdapter("SELECT * FROM myTable", conn)
Dim ds As New DataSet("myTable")
da.Fill(ds, "myTable")
DataGrid1.DataSource = ds.Tables("myTable").DefaultVIEw
End Sub
'浏覽存儲過程
Private Sub btnVIEwSP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnVIEwSP.Click
conn = New SqlConnection(ConnectionString)
If conn.State = ConnectionState.Open Then
conn.Close()
End If
ConnectionString = "Data Source=.;Initial Catalog=MyDataBase;User Id=sa;PassWord=;"
conn.ConnectionString = ConnectionString
conn.Open()
Dim da As New SqlDataAdapter("myProc", conn)
Dim ds As New DataSet("SP")
da.Fill(ds, "SP")
DataGrid1.DataSource = ds.DefaultVIEwManager
End Sub
'浏覽視圖
Private Sub btnViewVIEw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnViewVIEw.Click
conn = New SqlConnection(ConnectionString)
If conn.State = ConnectionState.Open Then
conn.Close()
End If
ConnectionString = "Data Source=.;Initial Catalog=MyDataBase;User Id=sa;PassWord=;"
conn.ConnectionString = ConnectionString
conn.Open()
Dim da As New SqlDataAdapter("SELECT * FROM myVIEw", conn)
Dim ds As New DataSet()
da.Fill(ds)
DataGrid1.DataSource = ds.DefaultVIEwManager
End Sub
Private Sub ExecuteSQLStmt(ByVal sql As String)
conn = New SqlConnection(ConnectionString)
' 打開連接
If conn.State = ConnectionState.Open Then
conn.Close()
End If
ConnectionString = "Data Source=.;Initial Catalog=MyDataBase;User Id=sa;PassWord=;"
conn.ConnectionString = ConnectionString
conn.Open()
cmd = New SqlCommand(sql, conn)
Try
cmd.ExecuteNonQuery()
Catch ae As SqlException
MessageBox.Show(ae.Message.ToString())
End Try
End Sub
End Class