RedDevil
RedDevil

Reputation: 35

Pass XML from C# to SQL Server

I'm trying to send XML in following format from C# (DataType string) to SQL Server stored proc:

<Content> </Content>

There is a space which should get stored as it is in SQL Server column. But it gets stored like <Content/>. So in nutshell there is loss of space from c# to SQL Server.

Is there anyway I can avoid this?

Upvotes: 1

Views: 380

Answers (3)

Fischermaen
Fischermaen

Reputation: 12468

You can add an attribute xml:space="preserve". That helps in "normal" serialization context, I don't know if it will help you in your special context.

Upvotes: 1

Alexander Mavrinsky
Alexander Mavrinsky

Reputation: 465

have you tried to use <!CDATA[ ]>?

Upvotes: 0

Randolpho
Randolpho

Reputation: 56419

The two fragments are equivalent; SQL server is just optimizing the XML.

Is there a particular reason you need the space in there? If so, you might try xml:space="preserve", like so:

<Content xml:space="preserve"> </Content>

Upvotes: 2

Related Questions