adapter.SelectCommand = new SqlCommand(strSql,conn); // Build the DataSet DataSet ds = new DataSet(); adapter.Fill(ds, employees); // Get a FileStream object FileStream fs = new FileStream(strFileName,FileMode.OpenOrCreate,FileAccess.Write); // Apply the WriteXml method to write an XML document ds.WriteXml(fs); fs.Close(); } } 十一、用ADO添加数据到数据库中: using System; using System.Data; using System.Data.OleDb; class TestADO { static void Main(string[] args) { string strDSN = Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:\test.mdb; string strSQL = INSERT INTO Employee(FirstName, LastName) VALUES('FirstName', 'LastName') ; // create Objects of ADOConnection and ADOCommand OleDbConnection conn = new OleDbConnection(strDSN); OleDbCommand cmd = new OleDbCommand( strSQL, conn ); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (Exception e) { Console.WriteLine(Oooops. I did it again:\n{0}, e.Message); } finally { conn.Close(); } } } 十二、使用OLEConn连接数据库: using System; using System.Data; using System.Data.OleDb; class TestADO { static void Main(string[] args) { string strDSN = Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:\test.mdb; string strSQL = SELECT * FROM employee ; |