there is a code

connection.Open(); SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandText = @"INSERT INTO innXml (inn,xml) VALUES (@inn, @xml)"; command.Parameters.Add("@inn", SqlDbType.NVarChar, 50); command.Parameters.Add("@xml", SqlDbType.Xml); this.Text = openFileDialog1.FileName; 

inn with the VarChar type everything is normally written to the database. But I don’t understand how to deal with the xml file. It is advisable to give an example of code I only understand c # =)))

  • cell has xml type. Is it possible to put there the entire xml file to download later? - Side Kick
  • do you pass value to parameter? command.Parameters.Add ("@ xml", SqlDbType.Xml) .Value = myXml; what error come out? - Ruslan_K
  • no mistake. just an empty cell in the database ( - Side Kick
  • I understand that you can make a byte array and just push it into a cell. But I would like the xml file itself. - Side Kick

1 answer 1

XML is the most common text, but written according to special rules that do not prevent it from being text. An XML file is a plain text file with the .xml extension that is needed only by the user and sometimes the OS to open the file in a user-friendly program.

The xml type in SQL differs from other text types only in additional functionality that can be applied to cells of this type (LIKE is not supported, XPath is supported, etc.). In terms of data storage, this is a plain text type. Therefore, you can safely pass a string that represents valid XML to the parameters. How you get it does not matter, read from the file or apply something like XElement.Tostring() .