Wednesday, March 17, 2010

reating XML file using StreamWriter

string xmlString = string.Empty;

       
        SqlConnection cn = new SqlConnection(connectionString);
        SqlCommand cmd = new SqlCommand(stringName, cn);
        SqlDataReader dr;
        cmd.ExecuteNonQuery();
        xmlString += " " ;
        xmlString += "";
        while (dr.Read())
        {
            xmlString += "";
            xmlString += dr[0].ToString();
            xmlString += "";
            xmlString += dr[1].ToString();
            xmlString += "";

        }
        xmlString += "";
        StreamWriter streamWriter = File.CreateText("D:\ampl.xml");
        streamWriter.WriteLine(xmlString);
        streamWriter.Close();