以Windows形式备份数据库表 [英] backing up tables of database in windows form

查看:70
本文介绍了以Windows形式备份数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,
我正在建立一个Windows Form应用程序,并且正在处理基于服务的数据库,我想要一种方法来备份我的所有数据库,我该怎么做?我听说过csv文件,但是我对此并不了解,您能帮我备份数据库吗?供将来使用

sir,
i am building up a windows form app, and i am dealing with service based database, i want a method to backup my all database, how can i do that? i heard about csv file, but i dont know much about that, can you help me to backup my database. for future use

推荐答案

这在很大程度上取决于您所使用的数据库产品,例如您可以发出SQL命令来导出数据库.但是,假设您没有该功能并保持简单,可以尝试使用类似的方法...
It depends very much on which database product you are using e.g. you could issue the SQL command to export the database. But assuming you don''t have that facility and keeping it simple, you could try something like this ...
DataSet ds = new DataSet(tablename);
            SqlDataAdapter da = new SqlDataAdapter("Select * from " + tablename, GetConnection());
            da.Fill(ds);
            ds.WriteXml(Path.Combine(foldername, tablename) + ".xml", XmlWriteMode.WriteSchema);



这将为每个表提供一个XML文件,如何再次获取所有表名取决于您正在使用的数据库.

C#对这种事情有很多支持-有关更完整的解决方案,请尝试阅读
使用C#和.NET 2.0的SQL Server 2005数据库备份和还原 [ ^ ] [ ]



This will give you one XML file per table, how you get all the table names again depends on the database you''re using.

There''s lots of support in C# for this sort of thing - for a more complete solution try reading
SQL Server 2005 Database Backup and Restore using C# and .NET 2.0[^][]


这篇关于以Windows形式备份数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆