Suppose I have a VarBinary[MAX] column, can I insert or update into that column using a type derived from System.IO.Stream? How?
I think that I can obtain a read-only stream from such a column using a SqlDataReader
, calling GetSqlBytes() on the reader, getting the SqlBytes instance, and then referencing the Stream property on that.
What I want is the converse - I want a stream for update or insert.
Possible? (from c#... Without writing T-SQL ?)
EDIT
I've seen code like this:
System.Data.SqlClient.SqlCommand _SqlCommand
= new System.Data.SqlClient.SqlCommand(_SQL, _SqlConnection);
// Convert image to memory stream
System.IO.MemoryStream _MemoryStream = new System.IO.MemoryStream();
_Image.Save(_MemoryStream, _ImageFormat);
// Add image as SQL parameter
System.Data.SqlClient.SqlParameter _SqlParameter
= new System.Data.SqlClient.SqlParameter("@" + _ImageFieldName, SqlDbType.Image);
_SqlParameter.Value = _MemoryStream.ToArray();
_SqlCommand.Parameters.Add(_SqlParameter);
// Executes a Transact-SQL statement against the connection
// and returns the number of rows affected.
_SqlRetVal = _SqlCommand.ExecuteNonQuery();
// Dispose command
_SqlCommand.Dispose();
_SqlCommand = null;
...but I don't want to use an array to specify the value. That works for small data sizes, but not as sizes get larger. I want to write into a stream.