What SqlDbType maps to varChar(max)? SqlDbType.VarChar says that it is limited to 8K, though that may be a documentation error.
-
Currently I see 3 different answers, which solution did you actually use?– edosoftMay 10, 2010 at 19:26
-
In the end I found that not explicitly setting the SqlDbType was the best way to go. It is far less error prone and doesn't have to be changed when the stored proc is changed.– Jonathan AllenMay 10, 2010 at 23:55
-
2But now your code is building an execution plan every time a different length string is passed to the SP. It's not optimal. MSDN shows to use -1, as eglasius states below.– HardCodeOct 25, 2010 at 17:52
-
Good point, but still not worth the pain.– Jonathan AllenFeb 18, 2015 at 22:50
3 Answers
Actually you can use it with VarChar. If it is a parameter you can build it with: new SqlParameter("@myparam", SqlDbType.NVarChar, -1)
-
1
-
1related question stackoverflow.com/questions/973260/… Jan 23, 2013 at 20:42
OK... Finally figured this out... if you get an error stating : " String[0]: the Size property has an invalid size of 0." You merely have to set the size parameter of the output SQL Parameter as so:
Dim parameter As SqlParameter = New SqlParameter("@FinalImportCount", SqlDbType.NVarChar)
parameter.Direction = ParameterDirection.Output
parameter.Size = 4000
cmd.Parameters.Add(parameter)
Hope this helps someone -- been trying to figure this out for 2 hours.... grrrrr.