Insert XML data in SQL Table using C# and VB.Net in ASP.Net

Last Reply 9 months ago By pandeyism

Posted 9 months ago

Hello, I am trying to load an XML file to a sql table from C #, what I do is create a stored procedure in the database and send an XML type parameter, but I always receive this error


public void executeLoadXML()
    string StrCon = "Connection String";
    bool success = false;
    string xml = @"<?xml version=""1.0"" encoding=""utf-8""?>  
            <soap:Envelope xmlns:soap="""" xmlns:xsi="""" xmlns:xsd="""">
                    <RetrieveUserByLoginResponse xmlns="""">


        using (SqlConnection con = new SqlConnection(StrCon))
            using (SqlCommand command = new SqlCommand("pruebaImport_XMLtoSql", con))
                command.CommandType = CommandType.StoredProcedure;
                command.CommandTimeout = 3600;
                SqlParameter parameter1 = command.Parameters.Add("@xml", SqlDbType.Xml);
                parameter1.Value = xml.ToString();
    catch (Exception ex)
        throw ex;


The problem seems to be in this line "<? Xml version =" "1.0" "encoding =" "utf-8" "?> But, please, do not ask me to delete it because I can not do it because I am consuming a web services and the response always bring this "<? xml version = "" 1.0 "" encoding = "" UTF-8 ""?>, I only made this example so that they understand me.

Thank you

This question does not have replies that have been liked.