Hi I'm getting a strange error need another set of eyes
I have this code:
con.Open();
var cmd = new SqlCommand("INSERT INTO [lntmuser].[attach] ([sysid],[name],[att_size],[cid],[flags],[contents]) VALUES (@sysid, @name, @att_size, @cid, @flags, @contents)", con) { CommandType = CommandType.Text };
(Blah, Blah, ASIGN FIRST 5 VALUES, These All work)
cmd.Parameters.AddWithValue("@contents", SqlDbType.Image).Value = aa.contents ?? (object) DBNull.Value;
Where aa.contents is of type byte[]. At first tried without
"?? (object) DBNull.Value;"
and I got a "insert expects @contents parameter" so I added the ?? (object) DBNull.Value; and now I get the following ugly error when I run my unit test:
RestoreTest.TestMultiParAttLookUp : FailedSystem.Data.SqlClient.SqlException : Operand type clash: nvarchar is incompatible with image
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at bcDAL.RestoreFunc.ExecuteSQL(List`1 emailIds, List`1 attIds, String conStrA, String conStrM) in RestoreFunc.cs: line 173
at bcDAL.RestoreFunc.RestoreEntry(String sysid, String conStrA, String conStrM) in RestoreFunc.cs: line 22
at tcUnitTests.RestoreTest.TestMultiParAttLookUp() in RestoreTest.cs: line 18
Where does nvarchar have come in to play ? I was looking at this question however I am explicitly stating the SQL Datatype before I assign the value.
I might just need some sleep lol. Thanks in advance.