sql - Implicit conversion from data type nvarchar to varbinary(max) is not allowed -


When I try to insert a DBNull.Value in a faucet varbinary this exception (max.)

) Field:

  Data type indirect conversion from nvarchar to varbinary (max) is not allowed Use this CONVERT function to run this query.   

Thats my code:

  insertCMD.Parameters.AddWithValue ("@ ErrorScreenshot", SqlDbType.VarBinary) .Value = DBNull.Value;   

I know there are duplicate questions on the SO but I do not use any string like others do the use.

Am I wrong?

Update: insertCMD = new SqlCommand ("TestplanTeststep (TeststepId, TestplanId, CreatedAt, ErrorText, ErrorScreenshot, TestState) using values ​​(@TeststepId, @ TestplanId, @EndAt, @ inserting ErrorText, @ ErrorScreenshot, @ TestState) ", thief)) {var p1 = insertCMD.Parameters.Add (" @ TeststepId ", SqlDbType.Int); Var p2 = insertCMD.Parameters.Add ("created @", SqlDbType.DateTime); InsertCMD.Parameters.AddWithValue ("@ TestplanId", testplan.id); InsertCMD.Parameters.AddWithValue ("Error Text", (Object) DBNull.Value; InsertCMD.Parameters.AddWithValue ("Error Screenshot", (Object) DBNull.Value); InsertCMD.Parameters.AddWithValue ("@TestState", (int) teststep.TeststepTestState.Untested); Foreign (teststep phase in teststeps) {p1.Value = step.Id; P2.Value = step.CreatedAt; InsertCMD.ExecuteNonQuery (); }}

Why not change your SQL:

 <<>> <<>>  Test < Include in prices (@TeststepId, @TestplanID, Created, @TestState)   

... and

Otherwise, try it in two rows I:

If it is always a tap, then it will have an effect.

Otherwise, check it in two rows:

  var Binary1 = insertCMD.Parameters.Add ("@usercrowshotshot", SqlDbType.VarBinary, -1); Binary 1 Value = DBNull.Value; Otherwise, in your original SQL insert statement, you are not defining the parameter type, but passing in varbinary, so error.   

Comments