Sqlconnection con = DB. mysqlconnection ();
Sqldataadapter da = New Sqldataadapter ( "SQL statement " );
Dataset DS = New Dataset ();
Da. Fill (DS );
System. Text. stringbuilder sb = New System. Text. stringbuilder ();
If (Ds. Tables [ 0 ]. Rows. Count > 0 )
{
Int I = 0 ;
For ( Int N = 0 ; N < DS. Tables [ 0 ]. Rows. Count; n ++ )
{
For ( Int M = 0 ; M < DS. Tables [ 0 ]. Columns. Count; m ++ )
{
I ++ ;
SB. append (Ds. Tables [ 0 ]. Rows [N] [M]. tostring ());
If (I % 11 ! = 0 )
{
SB. append ( " , " );
}
Else
{ Break ;}
}
SB. append ( " \ R \ n " );
}
Page. response. Clear ();
Page. response. Buffer = True ;
Page. response. charset = " Gb2312 " ;
Page. response. appendheader ( " Content-Disposition " , " Attachment=filename=abc.txt " );
Page. response. contentencoding = System. Text. encoding. getencoding ( " Gb2312 " ); // Set the output stream to simplified Chinese
Response. contenttype = " Text/plain " ; // Set the output file type to TXT.
This . Enableviewstate = False ;
System. Globalization. cultureinfo mycitrad = New System. Globalization. cultureinfo ( " ZH-CN " , True );
System. Io. stringwriter ostringwriter = New System. Io. stringwriter (mycitrad );
Page. response. Write (sb. tostring ());
Page. response. End ();
}
Con. Close ();