How to Export or Import complete database to another database using c#
Please help me to create a Export like Export and Im开发者_运维技巧port Opttion in in SQL Server 2005
Are you looking for something like this or this?
EDIT: Here is another example.
Here's an example.
Just send the needed sql statement to the server with a SqlCommand.ExecuteNonQuery()
.
For Backup:
BACKUP DATABASE [YourDatabaseName] TO DISK = N'FileName' WITH NOFORMAT, INIT, NAME = N'YourDatabaseName', SKIP, NOREWIND, NOUNLOAD, STATS = 10
For Restore:
RESTORE DATABASE [YourDatabaseName] FROM DISK = N'FileName' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10
Or if you like just use (like already mentioned by others) the SqlBulkCopy class.
SqlBulkCopy can be used to import/export data to/from a SQL Server database. Here is an article articles with example code: www.codeproject.com/KB/database/Cs_CSV_import_export.aspx
Also SMO can be used as in this example code from Microsoft on how to backup and restore a database with C#: https://msdn.microsoft.com/en-us/library/ms162133.aspx.
精彩评论