Employers - Post Free Jobs
Forum guidelines
  • Home
  • »
  • C# Language
  • »
  • How to pass XML as input paramter from c# code to SQL Table
AuthorQuestion
How to pass XML as input paramter from c# code to SQL Table
Posted on: 01 Apr 2013
 

Hi,

My Table column type is XML.

I am passing data to table by parsing string  into XML and passed as a parameter from C# code.

I am doing in below stepà
public static string ObjectToXml(SalesPurchase salesPurchase)
        {
            System.IO.StringWriter output = new System.IO.StringWriter();
            XmlSerializer xs = new XmlSerializer(salesPurchase.GetType());
            xs.Serialize(output, salesPurchase);
            return output.ToString();

        }

HERE I AM PASSING XML AS A INPUT PARAMETER TO STORED PROCEDUREà
public static bool SaveXML(Sales111 salesPurchase)
        {
            int recordsAffected = 0;
            string orderXml = ObjectToXml(salesPurchase);
            XElement planPropertyElement = XElement.Parse(orderXml);
            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                SqlParameter[] parms = new SqlParameter[3];
                parms[0] = new SqlParameter("@Id", salesPurchase.ReportingCustomerId);
                parms[1] = new SqlParameter("@SesId", salesPurchase.SessionId);
                parms[2] = new SqlParameter("@CenXml", planPropertyElement);
                try
                {
                    recordsAffected = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "usp_PSaveXml", parms);
                }
                catch (Exception ex)
                {
                    string str = ex.Message.ToString();
                }
            }

            return recordsAffected > 0 ? true : false;

        }

I AM GETTING BELOW EXCEPTIONà

No mapping exists from object type System.Xml.Linq.XElement to a known managed provider native type.
How i overcome it ?Please suggest any approach!!


Maggy!!!
AuthorReply
Jignesh Trivedi
  • 0
  • 0
accepted
Re: How to pass XML as input paramter from c# code to SQL Table
Posted on: 02 Apr 2013   Accepted Answer

hi,

I think this problem is due to passing XML object within parameter
please refer
http://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/d1666d13-dea3-4ce8-a818-6b852a63de4f/
it might help you.


Employers - Post Free Jobs

SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.