[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1021
  • Last Modified:

load xml into c# dataset

hey guys -

i have an xml schema in a dataset called "FormData".

then i have this function where i am trying to load in an xml file generated by a stored procedure.
the problem is that it seems that my dataset isn't getting populated. whenever i do the writeline debugging - it does actually print the data being returned by the stored proc (sql 2k5), but it doesn't fill the dataset it seems when i call it in my main function and try to databind the contents of it to a combo box.  i do know that the schema returned by my stored proc does match the xml returned by my stored proc

do you guys see anything i'm doing wrong?

  public static void LoadDataSet(string connection, string sp, ref FormData dataset)
        {
            if (dataset == null)
                return;

            SqlConnection connDB = new SqlConnection(connection);
            connDB.Open();
            SqlCommand cmdDB = connDB.CreateCommand();
            cmdDB.CommandText = String.Concat("exec ", sp);

            XmlReader sDB = cmdDB.ExecuteXmlReader();
            sDB.Read();
            while (sDB.ReadState != ReadState.EndOfFile)
            {
                System.Diagnostics.Debug.WriteLine(sDB.ReadOuterXml());
                dataset.ReadXml(sDB);
            }
            connDB.Close();
            dataset.AcceptChanges();
        }

main()
{
  FormData myDS = new FormData();
  LoadDataSet(@"server;Uid=user;Pwd=pass;",
                         "spanme", ref myDS);
            ddlState.DataSource = myDS;
            ddlState.DisplayMember = "State";

...

}

ideas??

thanks guys :)
0
sclaple
Asked:
sclaple
  • 2
1 Solution
 
JimBrandleyCommented:
I see two possible issues:
1. The XmlReader is a forward only reader. So, I expect:
System.Diagnostics.Debug.WriteLine(sDB.ReadOuterXml());
exhausts the input stream and leaves nothing for:
dataset.ReadXml(sDB);

2. DataSet.ReadXml() wants to read both the schema and the data. Is it posssible that this is clearing the scheam you already have loaded in the DataSet?

Jim
0
 
sclapleAuthor Commented:
#1 fixed it. Thanks and sorry for the long reply!
0
 
JimBrandleyCommented:
Glad it worked. Good luck.

Jim
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now