i have a table in sqlserver having following fields
name,age,dateofborth,phonenumber
now i want to convert it into text file
how can i do this,
it is very urgent
plz provide a code for the same
i am using vs2005
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
HimanshuPosted Jan 18, 2007, 5:37 AM
Nipun TomarPosted Jan 17, 2007, 1:44 PM
If you want to do it through code, you can try the following:
FileStream fileStream = File.Open(@"C:\Temp\NewText.txt", FileMode.Create, FileAccess.Write, FileShare.None);
StreamWriter streamWriter = new StreamWriter(fileStream);
foreach (DataRow dr in dataSet.Tables[0]) //datSet having your required records
{
//change /t to required formatting you want
streamWriter.WriteLine(dr["ColumnName1"].ToString() + "/t" + dr["ColumnName2"].ToString());
}
streamWriter.Close();
fileStream.Close();
Hope this will help..