Using DBNull.Value with SqlParameter without knowing sqlDbType?

前端 未结 5 1336
有刺的猬
有刺的猬 2021-01-05 19:42

I\'m using a SqlParameter to pass in null values to a table for various columns that are nullable. The problem is that SqlParameter looks like it defaults to nv

5条回答
  •  迷失自我
    2021-01-05 20:14

    There’s another way to do this. You can still use AddWithValue, however use SqlBinary.Null instead of DBNull.Value:

    c.Parameters.AddWithValue(“@cfp”, SqlBinary.Null);

    Don’t forget to import System.Data.SqlTypes into your project.

    Source

提交回复
热议问题