代码改变世界

vb.net sqlserver

2010-07-28 21:36  zhangbaoyu  阅读(311)  评论(0编辑  收藏  举报

Dim   strcon   As   String
                Dim   strsql   As   String
                Dim   con   As   SqlConnection
                Dim   com   As   SqlCommand
                Dim   databasepath   As   String
                Dim   pos   As   Integer

                databasepath   =   Application.ExecutablePath
                pos   =   InStrRev(databasepath,   "\ ")
                databasepath   =   Mid(databasepath,   1,   pos)   &   "backup\databaseback.bak "
               
                strcon   =   "server=localhost;database=humanadministration;uid=cxl;pwd=cxl; "
                con   =   New   SqlConnection(strcon)
                strsql   =   "backup   database   yourdatabase   to   disk= ' "   &   databasepath   &   " ' "
                com   =   New   SqlCommand(strsql,   con)

                Try

                        con.Open()
                        com.ExecuteNonQuery()
                        MessageBox.Show( "数据库备份成功! ",   "信息提示: ",   MessageBoxButtons.OK,   MessageBoxIcon.Information)

                Catch   ex   As   Exception
                        MessageBox.Show(ex.Message,   "错误提示: ",   MessageBoxButtons.OK,   MessageBoxIcon.Exclamation)
                Finally
                        con.Close()
                End   Try