Method 1: SqlConnectionconnnewSqlConnection (); 2conn. connectionString & quot; Server127.0.0.1; UserIDsa; Passwordfdahgdrethj31313210212121; Databasenorthwind; PersistSecurityInfoTrue & quot; 3conn. open (); 4 SqlData first example method:
1 SqlConnection conn = new SqlConnection (); 2 conn. connectionString = "Server = 127.0.0.1; User ID = sa; Password = fdahgdrethj31313210212121; Database = northwind; Persist Security Info = True"; 3 conn. open (); 4 SqlDataAdapter da = new SqlDataAdapter ("select * from table", conn); 5 SqlCommandBuilder thisBulder = new SqlCommandBuilder (da); 6 DataSet ds = new DataSet (); 7 da. fill (ds); 8 ds. writeXml (@ "C: \ temp. xml ");
Method 2:
1 private void WriteXmlToFile(DataSet thisDataSet)2 {3 if (thisDataSet == null) { return; }4 // Create a file name to write to.5 string filename = "myXmlDoc.xml";6 // Create the FileStream to write with.7 System.IO.FileStream myFileStream = new System.IO.FileStream8 (filename, System.IO.FileMode.Create);9 // Create an XmlTextWriter with the fileStream.10 System.Xml.XmlTextWriter myXmlWriter =11 new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);12 // Write to the file with the WriteXml method.13 thisDataSet.WriteXml(myXmlWriter);14 myXmlWriter.Close();15 }
The above is the details of the two simple sample code for generating xml in the database. For more information, see other related articles in the first PHP community!