将数据从SQL Server导出到C#中的记事本 [英] Exporting data from sql server to notepad in c#

查看:85
本文介绍了将数据从SQL Server导出到C#中的记事本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用.net将数据从数据库导出到记事本.

I want export data from database to Notepad using .net.

推荐答案

可以使用SqlDataAdapter将sql数据读取到DataSet中,然后使用DataSet.WriteXml生成数据的文本文件.

例子:

You can use Using an SqlDataAdapter to read the sql data to a DataSet, you can then use DataSet.WriteXml to produce a text file of the data.

Example :

SqlConnection objConnection = new SqlConnection("Connection String");
System.Data.DataSet objDataSet = new System.Data.DataSet();
SqlCommand objCommand = new SqlCommand();
objCommand.Connection = objConnection;
//Initializing the adapter
SqlDataAdapter objDataAdapter = new SqlDataAdapter(objCommand);
//Creating the DataSet
objDataSet = new System.Data.DataSet();
//Filling the DataSet
objDataAdapter.Fill(objDataSet);
objDataSet.WriteXml(@"c:\LOG.TXT");
objCommand.Dispose();
objConnection.Close();


这篇关于将数据从SQL Server导出到C#中的记事本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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