当前位置:Gxlcms > mysql > 教你创建动态MSSQL数据库表(6)_MySQL

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

时间:2021-07-01 10:21:17 帮助过:13人阅读

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

人气教程排行