0

According to the following solution (https://stackoverflow.com/a/42976399/2825284):

cmd.Parameters.Add(new SqlParameter("@position", position) { UdtTypeName = "Geography" });

My code:

SqlGeography geographyfield = null;
sqlParameter.ParameterName = "@geographyfield";
sqlParameter.UdtTypeName = "Geography";

if (geographyfield != null)
    sqlParameter.Value = geographyfield;
else
    sqlParameter.Value = DBNull.Value; // or null, I get the same error

How I can send null values in Geography field if allow NULL?

I get this error:

UdtTypeName property must be set only for UDT parameters.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ejrr1085
  • 975
  • 2
  • 16
  • 29

2 Answers2

0

One option can be set data has min value or another unexpected value that you can take like a null or unset value. Is in sql value set this field has nullable?

Leo
  • 1
0

According Jeroen Mostert's comment this is the solution: SqlGeography.Null.

SqlGeography geographyfield = null;
sqlParameter.ParameterName = "@geographyfield";
sqlParameter.UdtTypeName = "Geography";

if (geographyfield != null)
    sqlParameter.Value = geographyfield;
else
    sqlParameter.Value = SqlGeography.Null;

Thanks Jeroen Mostert.

Ejrr1085
  • 975
  • 2
  • 16
  • 29