I am trying to save a file to an Image datatype using inline query.
INSERT INTO tblPDFInfo(FileImage, PdfFileName, FeedDateTime, HasProcessed)
VALUES(@fileBytes, @fileName, getutcdate(), 0)
and then if I use string.format then it is rendering the byte array to string and so it serves no luck.
Another way if I create a sqlcommand and
objCmd = new SqlCommand(strSQL, objConn, objTrans);
objFileDataParam = new SqlParameter("@fileBytes", SqlDbType.Image);
objFileDataParam.Value = (byte[])fileData;
objCmd.Parameters.Add(objFileDataParam);
objFileNameParam = new SqlParameter("@fileName", SqlDbType.VarChar);
objFileNameParam.Value = PDFfileName;
objCmd.Parameters.Add(objFileNameParam);
objCmd.CommandText = strSQL;
Then when firing the query it is saying
System.Data.SqlClient.SqlException: Must declare the scalar variable
“@fileBytes”
And if in inline query I am declaring the same variable then it too gives me error saying
System.Data.SqlClient.SqlException: The variable name ‘@fileBytes’
has already been declared. Variable names must be unique within a
query batch or stored procedure.
How could I correct this up to make it working. Well I am not bound to a specific datatype but I need to save the file and later on retrieve it too, I think the image datatype would be a good choice, but could not make it happen. Any suggestions would be really helping.
Try this,