Link to home
Start Free TrialLog in
Avatar of jim_bob_jim
jim_bob_jimFlag for United States of America

asked on

asp.net c# create dynamic xml from database

Hi guys,

I wonder can you help,

Im working off of the following example that creates xml to be passed back to the client based on a string array with populated names.  

here is the coded example from the following book Im working off "Ajax for Web Application Developers"

    private void SearchUsers()
    {
        string request = Request["request"].ToString();

        string usernameXml = "";
        string[] usernames = new string[3] { "Kris Hadlock", "Grace Hopper", "Pi Sheng" };

        foreach (string username in usernames)
        {
            if (username.ToLower().Substring(0, request.Length) == request.ToLower())
            {
                usernameXml += "<username><![CDATA[" + username + "]]></username>";
            }
        }

        usernameXml = "<?xml version='1.0' encoding='iso-8859-1' ?><usernames>" + usernameXml + "</usernames>";
        XmlDocument xDoc = new XmlDocument();
        xDoc.LoadXml(usernameXml);
        xDoc.Save(Response.OutputStream);
    }

I wish to achieve the same except I want to pull the usernames from the databse as part of a query and then parse them into the xml document.

Can someone show me how I could do this please?

Thanks very much!

Jimbo
ASKER CERTIFIED SOLUTION
Avatar of mrichmon
mrichmon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrichmon
mrichmon

One correction:
OleDbConnection objConn = new OleDbConnection(ConfigurationSettings.AppSettings["Name_Of_Your_Connection_String"]);

You then need to define your connection in the AppSettings.  If using .NET 2 then you can use the actual ConnectionStrings section instead of AppSettings
Avatar of jim_bob_jim

ASKER

Thank you very much.  I had got so close and your answer explained exactly what I was missing.

Much appreciated!!