欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

教你创建动态MSSQL 数据库表(6)_MySQL

程序员文章站 2024-02-13 11:38:46
...
 '浏览表数据
  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