Option Explicit
Dim sql As String
Private Sub Command1_Click() '生成新表
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
sql = "select * into [newtable] from jishijilu"
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\wd.mdb;Persist Security Info=False"
cn.Open
rs.CursorLocation = adUseClient
rs.Open sql, cn, adOpenDynamic, adLockOptimistic
End Sub
Private Sub Command2_Click() '删除新表
Dim cn As New ADODB.Connection '定义数据库的连接
Dim rs As New ADODB.Recordset
sql = "DROP TABLE [newtable];" ' from jishijilu" ’ 从数据库中清除一个表格,语法是:DROP TABLE "表格名";
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\wd.mdb;Persist Security Info=False"
cn.Open
rs.CursorLocation = adUseClient
rs.Open sql, cn, adOpenDynamic, adLockOptimistic
End Sub
Private Sub Command3_Click() '查询新表
Dim cn As New ADODB.Connection '定义数据库的连接
Dim rs As New ADODB.Recordset
sql = "select * from [newtable]"
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\wd.mdb;Persist Security Info=False"
cn.Open
rs.CursorLocation = adUseClient
rs.Open sql, cn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rs
End Sub
Private Sub Form_Load() '原表显示
Dim cn As New ADODB.Connection
sql = "select * from jishijilu "
Dim rs As New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\wd.mdb;Persist Security Info=False"
cn.Open
rs.CursorLocation = adUseClient
rs.Open sql, cn, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rs
End Sub
|