How to get the XML from the SQL Store Procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shilpareddy2787
    New Member
    • Nov 2007
    • 11

    How to get the XML from the SQL Store Procedure

    Hello,

    I am developing an application. In which I have to generate html output using a xml. I am getting the xml from sproc. Now I am not getting how to get that returned xml from store procedure in my c# application. can any one please help me

    Thanks
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    What have you tried so far?

    Comment

    • shweta123
      Recognized Expert Contributor
      • Nov 2006
      • 692

      #3
      Hi,

      You can define the output parameter in your c# code for getting the xml from stored procedure.
      e.g.

      Code:
         //define command object
                  OleDbCommand com = new OleDbCommand();
                  OleDbParameter p1 = new OleDbParameter();
                  p1.DbType = OleDbType.VarChar;
                  p1.Name = parameter name;
                  p1.Size = 4000;
                  //set the direction of the parameter as OUTPUT in order to get the returned xml from stored procedure
                  p1.Direction = ParameterDirection.Output;
      
                  //set the properties of command object
                  com.CommandText = "";
                  com.CommandType = CommandType.StoredProcedure;
                  com.Connection = con;
                  com.Parameters.Add(p1);
      
                  //execute the stored procedure
                  com.ExecuteNonQuery();
      Originally posted by shilpareddy2787
      Hello,

      I am developing an application. In which I have to generate html output using a xml. I am getting the xml from sproc. Now I am not getting how to get that returned xml from store procedure in my c# application. can any one please help me

      Thanks

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Do you just an XML version of the result table?
        DataTable objects have the WriteXML() function you could use.

        Comment

        Working...