Protected void btnxml2_click (Object sender, eventargs E)
{
Dataset DS = dsreadxml (server. mappath ("DB. xml "));
This. dtlcontent. datasource = Ds. Tables [0];
This. dtlcontent. databind ();
String SQL = string. empty;
Foreach (datarow DR in DS. Tables [0]. Rows)
{
SQL + = "insert into IMG (";
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 = conn;
Conn. open ();
Sqlinsertcommand. executenonquery ();
Conn. 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 ();
}
}