I have an xls file that I load and transform into binary as follows:
FileStream fs = new FileStream(physicalPath + "/cadastros/documentos/" + "AWS-Estudantes_" + Convert.ToString(System.DateTime.Now.Year) + "-" + Convert.ToString(System.DateTime.Now.Month) + "-" + Convert.ToString(System.DateTime.Now.Day) + ".xls", FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
_planilha = br.ReadBytes((Int32)fs.Length);
fs.Close();
br.Close();
Then I call my method to write to the database by passing filename and _planilha
which is byte[] _planilha
:
string binary = string.Empty;
for (int i = 0; i < _planilha.Length; i++)
{
binary += _planilha[i];
}
Here I get the data from within _planilha
:
providerFactory.ClearParameters();
providerFactory.SqlStat.Append("INSERT INTO BinaryFiles(Titulo,Arquivo) VALUES ('" + _fileName + "', CAST(CAST('" + binary + "' AS VARCHAR(MAX)) AS BINARY(8000))) ");
And here I write, in the bank my field is a binary(8000)
only that happens that it transforms the binary I created from xls into a binary. But I need to record just what I gave it to him. That is not happening because without the Cast(Cast
it of the conversion error.