Dim cmd As ADODB.Command
Dim cnn As ADODB.Connection
Dim sql As String
Dim str As String
Set cmd = New ADODB.Command
str = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=c:\1.mdb"
dim cnn as new adodb.connection
cnn.ConnectionString = str
cnn.Open
sql = "Create table new (nn text(10),nian text(5))"
With cmd
.ActiveConnection = cnn
.CommandText = sql
.CommandType = adCmdText
.Execute 
End With

解决方案 »

  1.   

    在cnn.ConnectionString = str前面加上这一句:
    Set cnn = New ADODB.Connection
      

  2.   

    .ActiveConnection = cnn应改为
    Set .ActiveConnection = cnn另外如楼上老兄所言在cnn.ConnectionString = str前面加上这一句:Set cnn = New ADODB.Connection
      

  3.   

    'Correct To Following Code:
    'Add the Reference of Microsoft ADO 2.x Library
    Private Sub Form_Load()
    Dim cmd As New ADODB.Command
    Dim cnn As New ADODB.Connection
    Dim sql As String
    Dim str As String
    'Set cmd = New ADODB.Command
    str = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=c:\CommConfig.mdb"
    cnn.ConnectionString = str
    cnn.Open
    sql = "Create table new (nn text(10),nian text(5))"
    With cmd
    .ActiveConnection = cnn
    .CommandText = sql
    .CommandType = adCmdText
    .Execute
    End With
    End Sub
      

  4.   

    现在一般都用Dim cnn As New ADODB.Connection
    代替Dim cnn As  ADODB.Connection
    Set cnn =New ADODB.ConnectionDim cmd As New ADODB.Command
    代替Dim cmd As ADODB.Command
    Set cmd = New ADODB.Command