نمونه کد : پشتیبان گیری و بازگردانی . Access DataBase

RIG

متخصص C#.net
کد:
[SIZE=2][COLOR=#0000ff]
using[/COLOR][/SIZE][SIZE=2] System;
[/SIZE][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2] System.Collections.Generic;
[/SIZE][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2] System.ComponentModel;
[/SIZE][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2] System.Data;
[/SIZE][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2] System.Drawing;
[/SIZE][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2] System.Linq;
[/SIZE][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2] System.Text;
[/SIZE][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2] System.Windows.Forms;
[/SIZE][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2] System.Data.OleDb;
[/SIZE][SIZE=2][COLOR=#0000ff]using[/COLOR][/SIZE][SIZE=2] System.IO;
[/SIZE][SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][SIZE=2] abk
{
[/SIZE][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]partial[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#2b91af]Form1[/COLOR][/SIZE][SIZE=2] : [/SIZE][SIZE=2][COLOR=#2b91af]Form
[/COLOR][/SIZE][SIZE=2]{
[/SIZE][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][SIZE=2] Form1()
{
InitializeComponent();
}
[/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2] button1_Click([/SIZE][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][SIZE=2] sender, [/SIZE][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][SIZE=2] e)
{
[/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] CurrentDatabasePath = [/SIZE][SIZE=2][COLOR=#2b91af]Environment[/COLOR][/SIZE][SIZE=2].CurrentDirectory + [/SIZE][SIZE=2][COLOR=#a31515]@"\db.mdb"[/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#2b91af]FolderBrowserDialog[/COLOR][/SIZE][SIZE=2] fbd = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#2b91af]FolderBrowserDialog[/COLOR][/SIZE][SIZE=2]();

[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (fbd.ShowDialog() == [/SIZE][SIZE=2][COLOR=#2b91af]DialogResult[/COLOR][/SIZE][SIZE=2].OK)
{
[/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] PathtobackUp = fbd.SelectedPath.ToString();
[/SIZE][SIZE=2][COLOR=#2b91af]File[/COLOR][/SIZE][SIZE=2].Copy(CurrentDatabasePath, PathtobackUp + [/SIZE][SIZE=2][COLOR=#a31515]@"\BackUp.bk"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][SIZE=2]); 
progressBar1.PerformStep();
[/SIZE][SIZE=2][COLOR=#2b91af]MessageBox[/COLOR][/SIZE][SIZE=2].Show([/SIZE][SIZE=2][COLOR=#a31515]"پشتیبان گیری با موفقیت انجام شد"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#a31515]"ایجاد پشتیبان"[/COLOR][/SIZE][SIZE=2]);
progressBar1.Value = 0;
}
}
 
[/SIZE][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2] button2_Click([/SIZE][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][SIZE=2] sender, [/SIZE][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][SIZE=2] e)
{
[/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] PathToRestoreDB = [/SIZE][SIZE=2][COLOR=#2b91af]Environment[/COLOR][/SIZE][SIZE=2].CurrentDirectory + [/SIZE][SIZE=2][COLOR=#a31515]@"\db.mdb"[/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#2b91af]OpenFileDialog[/COLOR][/SIZE][SIZE=2] ofd = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#2b91af]OpenFileDialog[/COLOR][/SIZE][SIZE=2]();
ofd.Filter = [/SIZE][SIZE=2][COLOR=#a31515]"Text file (*.bk)|*.bk"[/COLOR][/SIZE][SIZE=2];
[/SIZE][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][SIZE=2] (ofd.ShowDialog() == [/SIZE][SIZE=2][COLOR=#2b91af]DialogResult[/COLOR][/SIZE][SIZE=2].OK)
{
[/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] Filetorestore = ofd.FileName;
[/SIZE][SIZE=2][COLOR=#2b91af]File[/COLOR][/SIZE][SIZE=2].Copy(Filetorestore, PathToRestoreDB,[/SIZE][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][SIZE=2]);
progressBar1.PerformStep();
[/SIZE][SIZE=2][COLOR=#2b91af]MessageBox[/COLOR][/SIZE][SIZE=2].Show([/SIZE][SIZE=2][COLOR=#a31515]"پشتیبان با موفقیت بازگردانی شد"[/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#a31515]"بازگرداندن پشتیبان"[/COLOR][/SIZE][SIZE=2]);
progressBar1.PerformStep();
progressBar1.Value = 0;
} 
}
}
}
[/SIZE]
 

RIG

متخصص C#.net
موارد لازم دو button ایجاد و با زگردانی و یکprogressBar1 .
نکته : db در شاخه bin-debug باشد
 

negin17h

مدیر تالارهای مهندسی کامپیوتر و رباتیکمتخصص #C
مدیر تالار
برای این موضوع ، قبلاً تاپيک داشتیم. بگردید پيدا می کنید :gol:
 

rahgoshafan

عضو جدید
سلام
تو یه برنامه (البته توی عکسش واسه فروش) کنار همین بکاپ گیری یه چکباکس گذاشته بود واسه بکاپگیری اتوماتیک ...
چطور این کار بکنم ؟
 

Similar threads

بالا