Hello.
I have a procedure that (is supposed to) instert a byte[] into a varbinary-field in sql server.
Here's the code:
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("SP_InsertStuff", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Id", SqlDbType.UniqueIdentifier);
cmd.Parameters["@Id"].Value = pId; // pId is a Guid
cmd.Parameters.Add("@datetime", SqlDbType.DateTime);
cmd.Parameters["@datetime"].Value = datetime;
cmd.Parameters.Add("@bindata", SqlDbType.VarBinary);
cmd.Parameters["@ bindata"].Value = bindata; // bindata is a byte[]
try
{
conn.Open();
cmd.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
finally
{
conn.Close();
}
When I put a breakpoint in the code I can clearly see that the bindata contains lots of information. Everything seems to be working nice. Except, when I retrieve the data, or just look in my table, the bindata-column is empty (or poosibly just 1 byte size).
Why is this? Am I doing something wrong?
/D