Monday, 15 February 2010

c# - Can I use varbinary type to store image in SQL Server database? -


I am trying to store an image in my SQL server database, what datatype should I use?

In the code aspx.cs below, I am trying to read all the bytes from the input bytes and trying to store it in the database, but by byte [] The array is not updated correctly in the table, am I missing something?

  Secure Zero Page_load (Object Sender, EventArgs e) {Request.InputStream.Position = 0; Byte [] content = new byte [request.InputStream.label]; request. Input stream. Read (content, 0, (int.) Request. InputStream.Length); Con.Open (); Try {String query = "update tblImageUpload set" + IMAGE_ID + "= @imageBytes, where Image_ID = '" + CID + "' '; int i = 0; (CMD = new SQL command (query, conn)) Using (CMD.Pamators.ed ("@Ifhites", SQLDB type Verbari, content length) value = content; I = CMD.exequestone ();} Response.Write ("upload query =" + query); Write ("upload code =" + i);} hold (ex before) {Response.Write ("upload code =" + east);}    

< Div class = "post-text" itemprop = "text">

You You can use VARBINARY Yes.

You can use it like this:

  cmd.Parameters add ("@Ifhites", SqlDbType.VarBinaryMax); Cmd.Parameters ["imagebytes"]. Value = Content;    

No comments:

Post a Comment