Sto cercando di memorizzare un'immagine nel mio database SQL Server, quale tipo di dati dovrei usare?Posso usare il tipo varbinary per memorizzare l'immagine nel database di SQL Server?
Nel sottostante code aspx.cs
, sto cercando di leggere tutti i byte dalla richiesta inputstream e di memorizzarlo nel database, ma l'array byte[]
non viene aggiornato correttamente nella tabella. Mi sto perdendo qualcosa?
protected void Page_Load(object sender, EventArgs e)
{
Request.InputStream.Position = 0;
byte[] Contents = new byte[Request.InputStream.Length];
Request.InputStream.Read(Contents, 0, (int)Request.InputStream.Length);
con.Open();
try
{
string query = "update tblImageUpload set " + IMAGE_ID + " = @imageBytes where Image_ID='" + CID + "'";
int i = 0;
using (cmd = new SqlCommand(query, con))
{
cmd.Parameters.Add("@imageBytes", SqlDbType.VarBinary, Contents.Length).Value = Contents;
i = cmd.ExecuteNonQuery();
}
Response.Write("Upload Query = " + query);
Response.Write("Upload Code = " + i);
} catch (Exception ex) {
Response.Write("Upload Code=" + ex);
}
'è possibile utilizzare varbinary (max)' dispiace errore di battitura – MethodMan