.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Insert Image to SQL

Posted By:      Posted Date: August 29, 2010    Points: 0   Category :ASP.Net
Hi,   I am trying to get it right to store an avatar into SQL. I have written some stored procedures to do this.This works half and half. Problem im having is that when i execute the code I get a error stating:Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the convert funtion. Though it still loads the data into the databse correctly? The code C# and SQL looks like the following:Stream imgStream = _inputFile.PostedFile.InputStream; int imgLen = _inputFile.PostedFile.ContentLength; string imgContentType = _inputFile.PostedFile.ContentType; string imgName = filename; byte[] imgBinaryData = new byte[imgLen]; int n = imgStream.Read(imgBinaryData, 0, imgLen); SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["TreeLizardConnectionString"]); SqlCommand cmd = new SqlCommand("UploadAvatar", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Avatar", SqlDbType.Binary); cmd.Parameters.Add("@AvatarType", SqlDbType.NVarChar, 50); cmd.Parameters.Add("@AvatarContentType", SqlDbType.NVarChar, 50); cmd.Parameters.Add("@UserID", SqlDbType.Int, 4); cmd.Parameters[0].Value = imgBinaryData; cmd.Parameters[1].Value = imgName; cmd.Parameters[2].Value = imgContentType; cmd.Parameters[3].Value = _userID; conn.Open(); cmd.ExecuteNonQuery(); con

View Complete Post

More Related Resource Links

How to insert Image (jpeg) into MS Word Programmatically using VB.NET


Hi there,

Can someone help me on How to insert Image (jpeg) into MS Word Programmatically using VB.NET..not C#.NET??? Sad

I could hardly find any articles for the coding. Preferably using Bookmark...can i have the sample code.



Insert image into Infopath form and save to SharePoint as PDF file


I have an InfoPath web-enabled form in MOSS 2007, that is integrated with a K2 blackpoint process for an approval workflow.

Once the form (a Purchase Order request form) has been approved in the K2 workflow process, I switch the form view to a "print-friendly" view for the requestor to view from the browser.  However, now I need to go one step further with this scenario:

1) I need to somehow insert/embed an image with the scanned-in signature of the approver (likely stored in a SP doc library) at the signature line section of my form.  Also, what are the security requirements for storing such images, but not granting all users access to these (e.g. only services accounts that need to access this for embedding into the form, etc.)?

2) Then I need to convert this final "print-friendly" view of the form (with the signature image) to a PDF document so that I can store it in SharePoint (and email it to the requestor using K2's email event capabilities).

Can anyone help me with a solution to both of these requirement, or point me to some resources for this (even 3rd party components are open-game).



how to insert image in to WPF windows?

Hi  Hoiw to insert image into WPF UI? Thanks

Insert Image column in External content type

Hi,   I've created an external content type. It pulls in data from SQL Server Database. I need to have the first column as an image based on the value of one of the columns. Could anyone please suggest how to add a column so represent an image in external list.   Regards, Zia

insert image in email using wss 3.0

Hi i am trying to insert image in email body .The image is located in Sharepoint image library    string strEmails = GetEmails(strGroupName);               SPWeb thisWeb = SPControl.GetContextWeb(Context);               string strMyEmail = SPContext.Current.Web.CurrentUser.Email;               string toField = strEmails;               //string subject = rftDefaultValue.Text;               string body = rftDefaultValue.Text;               StringDictionary headers = new StringDictionary();               headers.Add("to", strEmails);               headers.Add("cc", strMyEmail);               headers.Add("from", strMyEmail);               headers.Add("subject",txtTitle.Text);               headers.Add("content-type", "text/html"); //This is the default type, so isn't neccessary.               bool success = SPUtility.SendEmail(thisWeb, head

How Do You Insert An Image From The Image Folder Into A Binary Column?

Hello Forum, How would I go about inserting an image that's in my images folder into a sql table column of datatype varbinary(MAX) ?    Thank you

insert image to database



i want to insert an image to my table from asp.net page or from asp.net webservice and code in c# please

thnak u

insert image in report viewer from sql server


Hi, good day, i am facing a difficult task, how to insert image to report viewer in excel file as the image below? i hope anyone can help me. i only have 2 days to finish this part. i am using microsoft visual studio 2005 the image is save in the server. how to display the image in excel file which i export it through the report viewer. the image max fize size is 5MB.


Insert image from Pictures List into InfoPath?



I have a very simple SP2010 Pictures List with some logos.  I have another basic SP List with some product records.  When the user clicks to Edit one of the product records, I would like to display the logo from the Picture List above the InfoPath Edit Form.  Shouldn't be too difficult, should it?

What type of control do I insert in the InfoPath Form to get it to choose the correct picture?  For example, if I click on an HP Printer in my product List, the Edit box should show you the HP logo above the form, based on word 'hp' the Vendor field in the form.

Any advice? :)

I don't belive the Data Connections allow you to add the actual picture from a Picture List, do they? 





How to insert Binary Image data from XML To Excel using XSLT


Hi All,

I had created a XSLT which converts the XML file generated from the system to the excel format. The XSLT has the styles required for this transformation.

Now i am told to insert image in one of the excel columns using XSLT. The image is in binary code format in the XML file.

Tried to google but could not found the syntaxes for this. Let me know if anyone has done the image embedding in excel using XSLT.


How to convert image class object to byte type in order to insert database


I am trying to resize images after uploading and than inserting them into my database.

Dim newMainImage As System.IO.Stream = System.IO.Stream.Null
resizedMainImage.Save(newMainImage, jgpEncoder, myEncoderParameters)
Dim newMain As Image = Image.FromStream(newMainImage)

I was able to resize it however I couldnt find a way to convert image object to byte() in order to

I need something like

Dim ImageContent(newMain.ContentLength - 1) As Byte

newMain.InputStream.Read(ImageContent, 0 , newMain.ContentLength)

I need to convert image object to a file type in order to get its contentlenght and use .inputStream.Read function. Or is there any other way?

how to insert image into sql server manually (without code)

Can someone please tell me how to insert image into SQL server 2005 manually - without code.

I'm set the field as data type "image" and tried classical copy paste method, but without result.


Insert Image into Sqlserver database by using c# asp.net

Insert Image into Sqlserver database by using c# asp.net

Insert value using Table Value Functions

a real gem in Sql Server 2008. mostly people still using Stored procedure may be they shifted to SQL Server but they are not using TVF right now.

Insert Rows with a GridView

In ASP.NET version 1.x, I used the footer on the DataGrid control to insert new rows by placing a series of TextBox, DropDownLists, CheckBoxes etc. controls on it and then handling a save button. This also works with the GridView in version 2.0 but with one major exception: if your data source is empty, the GridView will hide your footer (and header) and only display the EmptyDataText.

Built-in Functions - Text and Image Functions in SQL Server

Text and image functions operate on TEXT, NTEXT and IMAGE data types. These data types are deprecated with SQL Server 2005 and should be replaced by VARCHAR(MAX), NVARCHAR(MAX) and VARBINARY(MAX) when possible. Alternatively you can also consider storing large string values using XML data type. Text and image functions are nondeterministic.

Future versions of SQL Server will not support TEXT, NTEXT and IMAGE data types. Columns with TEXT / NTEXT data type do not support commonly used string functions such as LEN, LEFT, RIGHT, etc. Furthermore, due to the large size of TEXT data you''re likely to see performance issues if you store such data in the database. However, at times you can''t help but use the TEXT / NTEXT / IMAGE data types (for example when supporting 3rd party databases when you cannot change the schema) - this is when text and image functions come in handy.

Program for Format Conversion of An Image

.NET provides extensive support for image conversion. Any image can be processed from one format to another. Most common formats to which .NET have support for are .BMP, .EMF, .GIF, .ICO, .JPG, .PNG, .TIF and .WMF.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend