Private void btnout_click (Object sender, system. eventargs e ){
Dataset DS = new dataset ();
This. sqldataadapter1.fill (DS );
DS. writexml (server. mappath ("\ test. xml"), xmlwritemode. ignoreschema );
DS. writexmlschema (server. mappath ("\ test. XSD "));
}
Private void btninput_click (Object sender, system. eventargs e ){
Dataset DS = dsreadxml (server. mappath ("\ test. xml "));
This. datagrid1.datasource = Ds. Tables [0];
This. datagrid1.databind ();
String SQL = string. empty;
Foreach (datarow DR in DS. Tables [0]. Rows ){
SQL + = "insert into [webmenu] (";
For (INT I = 0; I <Ds. Tables [0]. Columns. Count; I ++ ){
SQL = SQL + Ds. Tables [0]. Columns [I]. columnname. tostring () + ",";
}
SQL = SQL. substring (0, SQL. Length-1) + ") values (";
For (INT x = 0; x <Ds. Tables [0]. Columns. Count; X ++ ){
SQL = SQL + "'" + Dr [X]. tostring (). Replace ("'", "'' ") + "',";
}
SQL = SQL. substring (0, SQL. Length-1) + ");";
}
Sqlcommand sqlinsertcommand = new sqlcommand ();
Sqlinsertcommand. commandtext = SQL;
Sqlinsertcommand. Connection = This. sqlconnection1;
Sqlconnection1.open ();
Sqlinsertcommand. executenonquery ();
Sqlconnection1.close ();
}
Public static dataset dsreadxml (string path ){
Dataset DS = new dataset ();
Filestream FS = NULL;
Streamreader reader = NULL;
Try {
FS = new filestream (path, filemode. Open, fileaccess. Read );
Reader = new streamreader (FS );
DS. readxml (Reader );
Return Ds;
}
Finally {
FS. Close ();
Reader. Close ();
}
}