NullReference
NullReference

Reputation: 4484

Is it possible to convert a C# string to a SqlChars?

I'm creating some unit tests for a piece of code that returns a SqlGeography type. To mock up the SqlGeography column I'd like to use SqlGeography.STLineFromText to create a line string. Problem is STLineFromText takes SqlChars as a parameter. Does anyone know how to convert a C# string to SqlChars?

Upvotes: 6

Views: 5432

Answers (3)

Nikola Bogdanović
Nikola Bogdanović

Reputation: 3213

Use this:

new SqlChars(text.ToCharArray());

Upvotes: 3

Abe Miessler
Abe Miessler

Reputation: 85046

You should be able to use the SqlChars constructor:

SqlChars c = new SqlChars("test".ToArray());

Upvotes: 2

SLaks
SLaks

Reputation: 887345

new SqlChars(new SqlString(text));

Upvotes: 14

Related Questions