[C#] DB 에서 XML 형식으로 가져오기


DataSet Sales;

//SQL 연결설정
SqlConnection sqlConnection;
SqlDataAdapter sqlDataAdapter;

sqlConnection = new SqlConnection(connectionString);

try
{
sqlDataAdapter = new SqlDataAdapter("Sales", sqlConnection);
sqlDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;

SqlParameter paramAGENT = new SqlParameter("@AGENT", SqlDbType.VarChar, 20);
paramAGENT.Value = AGENT;
sqlDataAdapter.SelectCommand.Parameters.Add(paramAGENT);

SqlParameter paramLanguage = new SqlParameter("@Language", SqlDbType.VarChar, 2);
paramLanguage.Value = Language;
sqlDataAdapter.SelectCommand.Parameters.Add(paramLanguage);
//

Sales= new DataSet();
sqlDataAdapter.Fill(Sales, "Sale");

XmlDocument xml = new XmlDocument();
xml.PreserveWhitespace = true;
xml.LoadXml(Sales.GetXml());

return xml.OuterXml.ToString();

}
catch (Exception ex)
{
//클라이언트에게 예외를 던진다.
throw ex;
}

finally
{
sqlConnection.Close();
}