问题1: MDI子窗体怎么居中啊!我已经有用
Sub CenterForm(frm As Form)                 '定义窗体居中过程
  frm.Move (Screen.Width - frm.Width) \ 2, (Screen.Height - frm.Height) \ 2
End Sub但好像没有用哦!问题2:关于DATAGRID控件的问题:
假如有一个TYPE表里面有BOOK_TYPE,DISK_TYPE两个字段,我怎么在控件中显示数据中的数据. 
前提:数据库已经连接 rs_type.open "select * from type",conn,……,……,-1
告诉我怎么进行添加,修改等操作,有例子最好。问题3: 数据备份问题!代码如下,不知道哪有错误,反正就是个空架子!
Dim Fsys As New FileSystemObject
Dim bckupFile As FilePrivate Sub Form_Load()
    Dim lastPath As String
    Dim lastDate As String
    Dim lastTime As String
    
    'Read Registry for previous settings stored
    lastPath = GetSetting(App.Title, "Settings", "BackupPath")
    lastDate = GetSetting(App.Title, "Settings", "BackupDate")
    lastTime = GetSetting(App.Title, "Settings", "BackupTime")
    
    If lastPath = "" Then
        lblLastPath.Caption = "以前没有备份"
        lblLastDate.Caption = " "
        lblLastTime.Caption = " "
    Else
        lblLastPath.Caption = lastPath
        lblLastDate.Caption = lastDate & "  (mm-dd-yy)"
        lblLastTime.Caption = lastTime
    End If
End SubPrivate Sub cmdsave_click()On Error Resume Next
    cmdSave.Enabled = False
    Label1.Caption = "备份正在进行中, 请稍等..."
    Label1.BackColor = vbGreen
    Label1.ForeColor = vbYellow
    Dim destination As String
    Dim Source As String
    Dim currDate, currTime As String
    currDate = Format$(Now, "mm - dd - yy")
    currTime = Format$(Now, "hh:mm:ss AM/PM")
    destination = File1.Path & "\" & "Library.mdb"
    Source = App.Path & "\Library.mdb"
    'MsgBox "Source : " & source
    'MsgBox "Destination : " & destination
    Set bckupFile = Fsys.GetFile(finalpath)
    bckupFile.Attributes = Compressed
    Fsys.CopyFile Source, destination, True
    'Saving Current Backup Details
    SaveSetting App.Title, "Settings", "BackupPath", destination
    SaveSetting App.Title, "Settings", "BackupDate", currDate
    SaveSetting App.Title, "Settings", "BackupTime", currTime
    Label1.Caption = "[email protected]"
    Label1.BackColor = vbYellow
    Label1.ForeColor = vbBlue
    cmdSave.Enabled = True
    MsgBox "备份完成", vbInformation, "备份"
    Unload Me
End SubPrivate Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
End SubPrivate Sub Dir1_Change()
    File1.Path = Dir1.Path
End Sub
问题4: 怎么在VB中附加SQL数据库呢?就是在SUB MAIN()事件的时候判断如果当前软件运行路径下如果有数据库则不附加,如果没有则附加! 有代码最好了~问题5:如何初始化数据啊?先谢谢各位大虾了!

解决方案 »

  1.   

    问题1: MDI子窗体怎么居中啊!我已经有用
    Sub CenterForm(frm As Form)                 '定义窗体居中过程
      frm.Move (Screen.Width - frm.Width) \ 2, (Screen.Height - frm.Height) \ 2
    End Sub
    Private Sub Form_Load()
     CenterForm Me
    End Sub
    Public Sub CenterForm(frm As Form)
      frm.Move (Screen.Width - frm.Width) \ 2, (Screen.Height - frm.Height) \ 2
    End Sub
      

  2.   

    Private Sub Command3_Click()
        If cmbDB.Text = "Access" Then
            Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mdbpath & ";Persist Security Info=False"
        Else
            Conn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & useId & ";pwd=" & pd1 & ";Data Source=" & serverName
        End If
            str1 = Text1.Text
            Set Rs = Conn.Execute(str1)
           If Not Rs.EOF Then
            Rs.MoveFirst
            MSFlexGrid3.Rows = Rs.RecordCount + 2
            MSFlexGrid3.Cols = Rs.Fields.Count
                For z = 0 To Rs.Fields.Count - 1
                    MSFlexGrid3.TextMatrix(0, z) = Rs.Fields(z).Name
                Next z       p = 1
           Do While Not Rs.EOF
               For n = 0 To Rs.Fields.Count - 1
                    If IsNull(Rs.Fields(n).Value) Then
                        tempz = "---"
                    Else
                        tempz = Rs.Fields(n).Value
                    End If
                    MSFlexGrid3.TextMatrix(p, n) = tempz
                Next n
                p = p + 1
                Rs.MoveNext
            Loop
            Rs.Close
           End If
            Conn.Close
    End Sub
      

  3.   

    Public Function fBackupDatabase_a(ByVal sBackUpfileName$ _
                                    , ByVal sDataBaseName$ _
                                    , Optional ByVal sIsAddBackup As Boolean = False _
                                    ) As String
                                    
        Dim iDb As ADODB.Connection
        Dim iConcStr$, iSql$, iReturn$
        
        On Error GoTo lbErr
        
        '创建对象
        Set iDb = New ADODB.Connection
        
        '连接数据库服务器,根据你的情况修改连接字符串
        iConcStr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=zj"
        iDb.Open iConcStr
        
        '生成数据库备份语句
        iSql = "backup database [" & sDataBaseName & "]" & vbCrLf & _
                "to disk='" & sBackUpfileName & "'" & vbCrLf & _
                "with description='" & "zj-backup at:" & Date & "(" & Time & ")'" & vbCrLf & _
                IIf(sIsAddBackup, "", ",init")
                
        iDb.Execute iSql
        GoTo lbExit
        
    lbErr:
        iReturn = Error
    lbExit:
        fBackupDatabase_a = iReturn
    End FunctionPublic Function fRestoreDatabase_a(ByVal sBackUpfileName$ _
                                    , ByVal sDataBaseName$ _
                                    , Optional ByVal sDataBasePath$ = "" _
                                    , Optional ByVal sBackupNumber& = 1 _
                                    , Optional ByVal sReplaceExist As Boolean = False _
                                    ) As String
        
        Dim iDb As ADODB.Connection, iRe As ADODB.Recordset
        Dim iConcStr$, iSql$, iReturn$, iI&
        
        On Error GoTo lbErr
        
        '创建对象
        Set iDb = New ADODB.Connection
        Set iRe = New ADODB.Recordset
        
        '连接数据库服务器,根据你的情况修改连接字符串
        iConcStr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Data Source=zj"
        iDb.Open iConcStr
        
        '得到还原后的数据库存放目录,如果没有指定,存放到SQL SERVER的DATA目录
        If sDataBasePath = "" Then
            iSql = "select filename from master..sysfiles"
            iRe.Open iSql, iDb, adOpenKeyset, adLockReadOnly
            iSql = iRe(0)
            iRe.Close
            sDataBasePath = Left(iSql, InStrRev(iSql, "\"))
        End If
        
        '检查数据库是否存在
        If sReplaceExist = False Then
            iSql = "select 1 from master..sysdatabases  where name='" & sDataBaseName & "'"
            iRe.Open iSql, iDb, adOpenKeyset, adLockReadOnly
            If iRe.EOF = False Then
                iReturn = "数据库已经存在!"
                iRe.Close
                GoTo lbExit
            End If
            iRe.Close
        End If
        
        '关闭用户进程,防止其它用户正在使用数据库,导致数据恢复失败
        iSql = "select spid from master..sysprocesses where dbid=db_id('" & sDataBaseName & "')"
        iRe.Open iSql, iDb, adOpenKeyset, adLockReadOnly
        While iRe.EOF = False
            iSql = "kill " & iRe(0)
            iDb.Execute iSql
            iRe.MoveNext
        Wend
        iRe.Close
        
        '获取数据库恢复信息
        iSql = "restore filelistonly from disk='" & sBackUpfileName & "'" & vbCrLf & _
            "with file=" & sBackupNumber
        iRe.Open iSql, iDb, adOpenKeyset, adLockReadOnly
        
        '生成数据库恢复语句
        iSql = "restore database [" & sDataBaseName & "]" & vbCrLf & _
            "from disk='" & sBackUpfileName & "'" & vbCrLf & _
            "with file=" & sBackupNumber & vbCrLf
        With iRe
            While Not .EOF
                iReturn = iRe("PhysicalName")
                iI = InStrRev(iReturn, ".")
                iReturn = IIf(iI = 0, "", Mid(iReturn, iI)) & "'"
                iSql = iSql & ",move '" & iRe("LogicalName") & _
                        "' to '" & sDataBasePath & sDataBaseName & iReturn & vbCrLf
                .MoveNext
            Wend
            .Close
        End With
        iSql = iSql & IIf(sReplaceExist, ",replace", "")
        
        iDb.Execute iSql
        iReturn = ""
        GoTo lbExit
        
    lbErr:
        iReturn = Error
    lbExit:
        fRestoreDatabase_a = iReturn
    End Function
      

  4.   

    '1.使子窗体居中
    Me.Move (MDIForm1.Width - Me.Width) \ 2, (MDIForm1.Height - Me.Height) \ 2