'浏览表数据 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