程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> SqlServer數據庫 >> 關於SqlServer >> 教你創建動態MSSQL 數據庫表(6)

教你創建動態MSSQL 數據庫表(6)

編輯:關於SqlServer
 '浏覽表數據
  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
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved