با عرض پوزش
در کد backup و Restore که براتون گذاشتم از یک کلاس استفاده کرده بودم که تمامی کدهای sql رو پوشش میده
با استفاده از این کلاس کد backup و Restore هم کار میکنه
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
static class Class1
{
public static void SetData(string str)
{
SqlConnection mconnection = new SqlConnection(// Address ConnectionString);
SqlCommand command = new SqlCommand(str, mconnection);
command.CommandType = CommandType.Text;
command.CommandText = str;
mconnection.Open();
try
{
command.ExecuteNonQuery();
}
catch (SqlException myerror)
{
MessageBox.Show("Error Connecting to Database: " + myerror.Message);
}
finally
{
mconnection.Close();
mconnection.Dispose();
}
}
public static DataTable GetData(string str)
{
SqlConnection nconnection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand(str, nconnection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = command;
DataTable dt = new DataTable();
try
{
adapter.Fill(dt);
}
catch (SqlException myerror)
{
MessageBox.Show("Error Connecting to Database: " + myerror.Message);
}
finally
{
nconnection.Dispose();
}
return dt;
}
}