public class TestADO { public static void Main() { SqlConnection conn = new SqlConnection(Data Source=localhost; Integrated Security=SSPI; Initial Catalog=pubs); SqlCommand cmd = new SqlCommand(SELECT * FROM employees, conn); try { conn.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Console.WriteLine(First Name: {0}, Last Name: {1}, reader.GetString(0), reader.GetString(1)); } reader.Close(); conn.Close(); } catch(Exception e) { Console.WriteLine(Exception Occured -->> {0},e); } } } 十、从SQL内读数据到XML: using System; using System.Data; using System.Xml; using System.Data.SqlClient; using System.IO; public class TestWriteXML { public static void Main() { String strFileName=c:/temp/output.xml; SqlConnection conn = new SqlConnection(server=localhost;uid=sa;pwd=;database=db); String strSql = SELECT FirstName, LastName FROM employees; SqlDataAdapter adapter = new SqlDataAdapter(); |