Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
There is one table in my database named as "address_book"......on the form there are two buttons named as "Backup" and "Restore"........when i m going to click on the backup button, it must generate the backup file of the table in the database on the "Desktop".........and when i click on the restore button it must ask to provide a path in a textbox.......so for that i requires a code in C#....
it very urgent.....plz help.
plz as provide some sort of explanation as i am a beginner
Posted
Updated 16-Feb-14 17:32pm
v3

 
Share this answer
 
Comments
Gaurav Manusmare 15-Feb-14 23:21pm    
thank u sir ........but still m not clear with the provided solution ...........can u plz explain it in detail or if possible then provide me accurate coading
OriginalGriff 16-Feb-14 4:00am    
How much more information do you need than working, fully commented code?
For Backup
just run this Procedure

SQL
create Procedure Proc_name
@name nvarchar(max)
as
begin
declare @db_name as nvarchar(max);
declare @filename as nvarchar(max);
select @db_name= name from sys.databases where name =@name
set @filename='D:\'+@db_name+'.bak'
backup database @db_name to disk =@filename;
end


and
C#
try
  {
     sqlConnection = new SqlConnection(dbConnectionString);
     SqlCommand command = new SqlCommand("Proc_name", sqlConnection);
     command.CommandType = CommandType.StoredProcedure;
   
     command.Parameters.Add("@Name", SqlDbType.String).Value = db_name;
     sqlConnection.Open();
     return command.ExecuteNonQuery();
     sqlConnection.Close();
  }
catch (SqlException ex)
  {
     Console.WriteLine("SQL Error" + ex.Message.ToString());
     return 0;
  }



if u have an authentication You can get the Backup on your C:
 
Share this answer
 
v2
Comments
Gaurav Manusmare 15-Feb-14 23:23pm    
thank u sir ........but still m not clear with the provided solution ...........can u plz explain that how can i you this procedure in my coading ...... if possible then provide me accurate coading as i am beginner
King Fisher 16-Feb-14 23:25pm    
updated

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900