Sqlconnection Conn = New Sqlconnection ();
Conn. connectionstring = " Server = 127.0.0.1; user id = sa; Password = fdahgdrethj31313210212121; database = northwind; persist Security info = true " ;
Conn. open ();
Sqldataadapter da = New Sqldataadapter ( " Select * from table " , Conn );
Sqlcommandbuilder thisbulder = New Sqlcommandbuilder (DA );
Dataset DS = New Dataset ();
Da. Fill (DS );
DS. writexml ( @" C: \ Temp. xml " );
========================================================== ==============================================
Private Void Writexmltofile (Dataset thisdataset) {
If (Thisdataset = Null ) {Return;}
// Create a file name to write.
String Filename = " Myxmldoc. xml " ;
// Create the filestream to write.
System. Io. filestream myfilestream = New System. Io. filestream
(Filename, system. Io. filemode. Create );
// Create an xmltextwriter with the filestream.
System. xml. xmltextwriter myxmlwriter =
New System. xml. xmltextwriter (myfilestream, system. Text. encoding. Unicode );
// Write to the file with the writexml method.
Thisdataset. writexml (myxmlwriter );
Myxmlwriter. Close ();
}