Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want export data from database to Notepad using .net.
Posted

1 solution

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 :

C#
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();
 
Share this answer
 
Comments
PrateekshaPH 16-Aug-11 4:12am    
Thank you :)
senthil sennu 16-Aug-11 4:23am    
If the above solution work, pls mark as answered. :)

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