Option Explicit
Dim conn As New Connection
Private Sub Command1_Click()
Dim strSQL As String
On Error GoTo ErrHandle
If conn.State = 0 Then
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\mytestdb1.mdb;Persist Security Info=False"
conn.Open
End If
strSQL = "CREATE TABLE " & Trim$(Text1) & "(id integer CONSTRAINT index1 UNIQUE,name TEXT,sex TEXT,question TEXT)"
conn.Execute strSQL
MsgBox "CREATE TABLE OK!", , "OK"
Exit Sub
ErrHandle:
Err.Raise Err.Number, "CREATE TABLE", Err.Description
End Sub
Private Sub Command2_Click()
Dim rs As New Recordset
Dim table1 As String
Dim strQuestion As String
On Error GoTo ErrHandle
If conn.State = 0 Then
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\mytestdb1.mdb;Persist Security Info=False"
conn.Open
End If
table1 = Text1
strQuestion = "What is his ege?"
rs.Open "select * from " & table1 & " where question='" + strQuestion + "'", conn, adOpenDynamic, adLockOptimistic
rs.AddNew
rs("id") = 1
rs("name") = "jack"
rs("sex") = "boy"
rs("question") = strQuestion
rs.Update
MsgBox "UPDATA TABLE OK!", , "OK"
Exit Sub
ErrHandle:
Err.Raise Err.Number, "UPDATE TABLE", Err.Description
End Sub
Private Sub Form_Load()
Text1 = "mytable"
End Sub
温馨提示:答案为网友推荐,仅供参考