How can I add a null value in a parameter varbinary datatype?
When I execute the following code:
using (SqlConnection myDatabaseConnection1 = new SqlConnection(myConnectionString.ConnectionString))
{
using (SqlCommand mySqlCommand = new SqlCommand("INSERT INTO Employee(EmpName, Image) Values(@EmpName, @Image)", myDatabaseConnection1))
{
mySqlCommand.Parameters.AddWithValue("@EmpName", textBoxEmpName.Text);
mySqlCommand.Parameters.AddWithValue("@Image", DBNull.Value);
myDatabaseConnection1.Open();
mySqlCommand.ExecuteNonQuery();
}
}
I get the following System.Data.SqlClient.SqlException
:
Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…