使用SQL查询从数据库中提取数据,并使用C#将数据写入文件 [英] Extract data from database using SQL query and write the data to a file using C#
问题描述
大家好,
Hi All,
如何从sql server表中提取数据并将其写入文件,我希望我设法使用resultSet.getString获取数据的逻辑但是这些值是我想要的两行,如下所示,并将输出写入文件。
how to extract data from sql server table and write it to a file , I want the logic I managed to get data using resultSet.getString but the values are in two lines I would like as belowand write the output to a file.
columnname1,columnname2
columnname1,columnname2
1234,567
resultSet.getString(i) --> resultSet.getString is giving out column values in new line can we combine to one line ?
查询: - 从表中选择*
Query:- select * from table
谢谢
Sri
Sri
Sri.Tummala
Sri.Tummala
推荐答案
https:// msdn.microsoft.com/en-us/library/haa3afyz(v=vs.110).aspx
reader.GetString(1));
您可以使用列名而不是序数列号。
You can use the columnname instead of ordinal column number.
然后,您知道如何将数据写入文本文件,这与ADO.NET Datareader无关。
Then it's a matter of you knowing how to write data to a text file, which is not part anything to do with an ADO.NET Datareader.
您必须像往常一样使用Textwritter格式化数据并将其写出来。
You'll have to format the data and write it out using a Textwritter as usual.
这篇关于使用SQL查询从数据库中提取数据,并使用C#将数据写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!