using System;
using System.Data;
using System.Xml;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace CSCommand
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string strConn, strSQL;
//strConn = "Provider=SQLOLEDB;User ID=sa;Password=gatsol;Initial Catalog=NorthWind;Data Source=211.236.186.207;";
strConn = ";User ID=sa;Password=gatsol;Initial Catalog=NorthWind;Data Source=211.236.186.207;";
//SqlConnection은 위에 주석 처리된 부분에 보이는 Provider를 지정하면 에러가 난다.
//SqlConnection은 기본적으로 MsSql 연결을 지원하기 때문에 Provider는 알수 없는 옵션인 것이다.
strSQL = "Select Top 2 CustomerID, CompanyName From Customers For Xml Auto, Elements";
SqlConnection cn = new SqlConnection(strConn);
cn.Open();
SqlCommand cmd = new SqlCommand(strSQL, cn);
XmlReader xdx= cmd.ExecuteXmlReader();
DataSet ds = new DataSet();
ds.ReadXml(xdx, XmlReadMode.Fragment);
xdx.Close();
cn.Close();
string strPathToXml = "C:\\MyData.xml";
ds.WriteXml(strPathToXml);
ShowXmlInIE(strPathToXml);
}
static void ShowXmlInIE(string strPathToXml)
{
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
object objEmpty = Type.Missing;
ie.Navigate(strPathToXml, ref objEmpty, ref objEmpty, ref objEmpty, ref objEmpty);
ie.Visible= true;
}
}
}