2

I have a SQL Server database with a column of type XML. I've been looking about for ways to populate it using an INSERT query / stored procedure from asp.net.

So far all I can find is ways to get (SELECT) the XML data and execute an SqlDataReader / XMLReader (such as this example)

How can I go about populating the column from ASP.NET? The xml will look something like the following:

<remarks>
    <remark>
        <author>...</author>
        <date>...</date>
        <content>...</content>
    </remark>
    <remark>
        <author>...</author>
        <date>...</date>
        <content>...</content>
    </remark>
</remarks>

The 'content' will be entered by a user in a textbox, and the other columns will be populated using DateTime.Now() and User.Identity.Name.

I am looking to be able to:

  1. Enter a first remark into an empty XML column.
  2. Enter additional remarks at a later time.

Can this be done? I can't manage to find any information on this.

1 Answer 1

3

This should do the trick for INSERT

INSERT INTO YourTable(idCol,xmlCol)
values(1,'<?xml version="1.0" encoding="utf-8"?>
<remarks>
    <remark>
        <author>...</author>
        <date>...</date>
        <content>...</content>
    </remark>
    <remark>
        <author>...</author>
        <date>...</date>
        <content>...</content>
    </remark>
</remarks>')

For UPDATE, I won't give a better answer than https://stackoverflow.com/a/1440688/1236044

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.