http://www.csdn.net/expert/topic/780/780826.xml?temp=.4466516

解决方案 »

  1.   

    Dim oSQLServer As New SQLDMO.SQLServer
    Dim sText As String
    Public Sub ConnServer()
        On Error GoTo HandlerErr
        Screen.MousePointer = vbHourglass
        If bConnected Then
            oSQLServer.DisConnect
            cmdOk.Enabled = False
        End If
        oSQLServer.LoginTimeout = 30
        oSQLServer.ODBCPrefix = False
        oSQLServer.Connect gSQLServer, gLogin, gPassword
        bConnected = True
        Screen.MousePointer = vbDefault
        
        Exit Sub
    HandlerErr:
        bConnected = False
        Screen.MousePointer = vbDefault
        MsgBox gsConnotConnect & vbCrLf & Err.Description, vbInformation, Me.CaptionEnd SubPrivate Sub cmdRun_Click()
        Dim iLine() As String
        
        If rtbSql.Text = "" Then   //这是你的sql语句。
            Exit Sub
        End If
        On Error GoTo HandlerErr
        gCN.BeginTrans
        iLine = Split(rtbSql.Text, Chr(13))
        For i = 0 To UBound(iLine)
            Select Case UCase(Replace(Trim(iLine(i)), Chr(10), ""))
                Case "GO"
                    gCN.Execute sText
                    sText = ""
                Case Else
                    sText = sText & vbCrLf & iLine(i)
            End Select
            gCN.Execute sText
        Next
        
        gCN.CommitTrans
        MsgBox "OK", vbInformation
        Exit Sub
    HandlerErr:
        gCN.RollbackTrans
        MsgBox Err.Description, vbInformation
        
    End Sub
    Private Sub Form_Load()
        ConnServer
    End Sub
      

  2.   

    SQL Server中:
    EXEC sp_rename 'customers.[contact title]', 'title', 'COLUMN'
    将customers表中的字段contact title名称改成title.
      

  3.   

    我是做Access和SQLServer双数据库的
      

  4.   

    adox怎么用啊,没有用过!!~写点相关代码好么,需要引用什么?
      

  5.   

    100% 好使aa.aaaaa=表名.字段名 
    cccc要改的字段名 
    Dim conn As New ADODB.Connection
    Private Sub Command1_Click()
    Set aa = conn.Execute("sp_rename 'aa.aaaaa', 'cccc'", adCmdStoredProc)
    End Sub
    Private Sub Form_Load()
    conn.Open ("driver={SQL Server};server=(local);uid=sa;database=hotyoung;pwd=aaa")
    End Sub
      

  6.   

    要是Access呢?我试验着使用Adox,可是也只是改动了表的名称,字段的还是没有做到!!~
    Private Sub Command1_Click()
    Dim x As New ADOX.Catalog
    Dim y As New ADOX.Table
    Dim II As Long
    x.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\试验区域\数据库\db4.mdb;Persist Security Info=False"
    'For II = 0 To x.Tables("aaa").Indexes.Count - 1
    '  Debug.Print x.Tables("aaa").Type
    'Next
    'x.Tables("aaa") = "bbb" 
    End Sub请关注
      

  7.   

    你查查 ALTER TABLE这个东西
      

  8.   

    ALTER TABLE不好用,有个Rename的方法,Ado不支持