How to save image in sql server and display that image in datagrid??

Hay Friend's

Can u plese send me the way how to save image in sql server and display that images in datagrid or other control also like Image control or Image control Button?? Plese send the coding in C#.

 Thank's

Amit

0
click_to_amit
6/27/2007 1:04:09 PM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

5 Replies
845 Views

Similar Articles

[PageSpeed] 23

try this link...it display image in data grid... 

http://www.odetocode.com/Articles/172.aspx

and for further reference you can refer

http://forums.asp.net/p/1122135/1754824.aspx#1754824

 

 


Regards
Amit
0
thakur_amit
6/27/2007 1:31:46 PM
Hi amit, thanks for ur link but I m not fully Satisfy.. so kindly Send me more solutions..

Thank's

Amit
0
click_to_amit
6/29/2007 9:27:03 AM
Hi Amit, Thanks for ur Link, but I m not fully Satisfy. So kindly send me more solutions 

Thanks

Amit
0
click_to_amit
6/29/2007 9:30:38 AM

Hi,

You can use stream object to insert the image to your database. Here's the sample for you to refer.

1.Store image in database:

Int64 intImageSize;
string strImageType;
Stream ImageStream;

// Gets the Size of the Image
intImageSize = PersonImage.PostedFile.ContentLength;

// Gets the Image Type
strImageType = PersonImage.PostedFile.ContentType;

// Reads the Image
ImageStream = PersonImage.PostedFile.InputStream;

byte[] ImageContent = new byte[intImageSize + 1];
int intStatus;
intStatus = ImageStream.Read(ImageContent, 0, intImageSize);

// Create Instance of Connection and Command Object
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"));
SqlCommand myCommand = new SqlCommand("sp_person_isp", myConnection);

// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;

// Add Parameters to SPROC
SqlParameter prmPersonImage = new SqlParameter("@PersonImage", SqlDbType.Image);
prmPersonImage.Value = ImageContent;
myCommand.Parameters.Add(prmPersonImage);

SqlParameter prmPersonImageType = new SqlParameter("@PersonImageType", SqlDbType.VarChar, 255);
prmPersonImageType.Value = strImageType;
myCommand.Parameters.Add(prmPersonImageType);

try {
	myConnection.Open();
	myCommand.ExecuteNonQuery();
	myConnection.Close();
	Response.Write("New person successfully added!");
}
catch (SqlException SQLexc) {
	Response.Write("Insert Failed. Error Details are: " + SQLexc.ToString());
}

 2. Retrieving Images from SqlServer and displaying in a DataGrid
<asp:TemplateColumn HeaderText="Image">
        <ItemTemplate>
            <asp:Image 
            Width="150" Height="125" 
            ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "PersonID")) %>' 
            Runat=server />
        </ItemTemplate>
</asp:TemplateColumn>
 
 
//And the method FormatURL (A Server side Function) is as follows. 
   public string FormatURL(object strArgument)
{
	return ("readrealimage.aspx?id=" + strArgument);
}
//And the method FormatURL (A Server side Function) is as follows. 
public string FormatURL(object strArgument)
{
	return ("readrealimage.aspx?id=" + strArgument);
}
 
///Database part
public void Page_Load(object sender, EventArgs e)
{

	string strImageID = Request.QueryString("id");

	// Create Instance of Connection and Command Object
	SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"));
	SqlCommand myCommand = new SqlCommand("Select PersonImageType, PersonImage from das_person_real_images Where PersonID=" + strImageID, myConnection);

	// I have used the select statement. But it would be much much better, if you 
	//could write a small stored procedure which contains the above sql statement.
	// Mark the Command as a SPROC (in case, if you wrote the stored procedure
	//myCommand.CommandType = CommandType.StoredProcedure

	try {
		myConnection.Open();
		SqlDataReader myDataReader;
		myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
		while ((myDataReader.Read())) {
			Response.ContentType = myDataReader.Item("PersonImageType");
			Response.BinaryWrite(myDataReader.Item("PersonImage"));
		}
		myConnection.Close();
	}
	catch (SqlException SQLexc) {

	}

}
 
Hope that helps. Thanks.

Michael Jin.
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Nai
7/2/2007 1:40:00 AM

Hi, this is an interesting post.  I am curious about if there is something similar you can do to display the SQL image field in a DataGrid in a Windows Forms application too?

Thanks in advance.

 Jim

0
jmarciniak
12/12/2007 1:00:36 AM
Reply:

Similar Artilces:

how to save link into sql server to folder that contain image.n Display the image in Mypage.aspx
>How to save only 3 image when user upload their image and store in folder that named by their ID. >After that i need the image to be display in aspx page base on loginID.How? can i use session(loginID)? >Is there any tutorial or code in VbScript to save link to image store in folder into database(Sql Server)...

display images from SQL Server image across intranet using ado.net filestream object
folks  i recently attended an MCPD boot camp where they taught me to access and store images using SQL Server and the filestream object.  Previously i had (sensibly) used a file server and impersonation to copy files. Uploading works fine.  Viewing works fine in debug so i rolled out an app in my work where the pics are uploaded and viewed across the intranet. to my horror i realised (too late!) that whilst it works fine in debug, it does not work when published. now no one but me can access these pics and it is a night mare.  the only documentation i have found ...

Display sql server image in image control
I am trying to display an image selected from an sqlserver image field in an asp image control.  I am not getting a result, no image being displayed.  Debug shows that there is data in the field so I think my problem is after the select statement.  I have listed the c# code as well at the markup.  Thanks for any help you can give me.public System.Drawing.Image RetrieveImage() {System.Drawing.Image image = null;SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["FoodService2005ConnectionString"].ConnectionString); {SqlCommand cmd = cn...

display image in Gridview from sql image in .Net 2005
Hi all, I need to Display the Image directly from SQL Database in the GridView as Thumnails. This i can do in .Net 2003 with Help of ItemDatabound Event and Template Column. But in the .Net 2005 there no ItemDatabound event in GridView. For Example I need to Show it like this:  Help Me ASAP.Tamil See :http://www.beansoftware.com/ASP.NET-Tutorials/Images-Database.aspxHope this helps. Vikram.S, DeveloperDiscountASP.NETInnovative ASP.NET Hosting & SQL Hosting Thanks a lot Sharma. It was very useful.  Tamil...

How to save a picture in a SQL image field and how to show a picture from a SQL image field
HI! I am searching now a real long time in the forum and I found a lot of stuff to this topic. But please help me it doesn't work! On my webapplication there is a possibility to save a private picture.If a new user is saved in the database I want to save a fixed picture as startpicture.Dim picturePath As String = Request.ServerVariables("APPL_PHYSICAL_PATH") & "img\anonymous.jpg" Please tell me the way how to save this anonymous.jpg from the picturePath into the database and after that how to display the picture. Thank you! .         ...

how to display image in the gridview. I have image name in the sql server table.
What am I supposed to do for displaying image in the gridview. What am I supposed to write in the aspx to display that secific image in the gridview from the database table. Thanking you in advance. Digish A D You can do this using BoundColumns in ASPX, Please find more details in the MSDN Link below http://msdn.microsoft.com/en-us/library/aa479350.aspx Since your image name is in database so you can manipulate the following line dr("PictureURL") = ResolveUrl("~/DisplayingImages/Images/Blue hills.jpg") and assign the database value in PictureURL.  See th...

How to SHOW (JPEG) saved images from SQL Server (image type) ?
Hello, I managed to save some processed JPEG files directly into the database (into an image field) How can I get it back from the database and show it ? Thanks, Yovav.10X N C U L8RBest RegardsYovavG@GMail.com Response.ContentType = GetContentTypeFromDB();Response.BinaryWrite(CreateThumbnail(GetDataFromDB(), width, height));private byte[] CreateThumbnail(byte[] data, double width, double height){System.Drawing.Image g = System.Drawing.Image.FromStream(new MemoryStream(Data));Size ThumbSize = new Size(); ThumbSize = NewThumbSize(g.Width, g.Height, Width, Height);Bitmap ImageOut...

Retrieving images from SQL SERVER and displaying in datagrid.
I was able to get this code to mostly work. Unfortuantely, the datagrid is displaying the same picture (in as many rows as records exist). Please advise. -------------------------------------------------------------------------------- DATAGRID PAGE: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here ADCN = Session("GADCN") If Not IsPostBack Then BindData() End If End Sub Function FormatURL(ByV...

How to display SQL Server Image column in a Image control in a web formview??
I have a SQL Server 2005 table with a column called WBTImage with a data type as image.  The images were already loaded into the table using a MSAccess program. I want to display the WBTImage column in a asp image control (imgTrain) on a web form.  There is no data binding property for the image column.  I have looked at many posts across many forumns and all of the solutions do not appear to work.  Some used the system.drawing,image.fromstream, some used binary.write, one showed a windows form with a data binding that I could not find and the other used a memorystream...

How do I retrieve and display an image from SQL Server into a DataGrid Column?
I have created a datagrid programatically. Everything works fine but I would like to add a datagrid column that retrieves (streams) and displays an image from an SQL column (of column type "image"). it all needs to be done at runtime. any ideas? Check out the Club Site Start kit or the Personal Web Site Starter Kit on this site.  They both have image utils.Whether you think you can or you think you can't; you're right.If Heaven ain't a lot like Detroit, then I don't wanna go... - Uncle Cracker http://www.odetocode.com/Articles/172.aspx "SELECT ImageKey, Im...

Save a Images into SQL Server Using VB.Net
I am trying to create a website that people can upload an image and have it saved to a database.  Can someone point me in the right direction on this?  What properties need to be saved in the db and how? Maybe this can help you http://www.dotnetspider.com/Question117.aspx http://www.vbdotnetheaven.com/UploadFile/aghiondea2/StoringImagesInVB11122005034248AM/StoringImagesInVB.aspx?ArticleID=7ed1fe42-0819-4912-88ae-bbc43829d8a6   hi, check this url, http://www.codeproject.com/KB/web-image/PicManager.aspx http://www.vbdotnetheaven.com/UploadFile/aghiondea2/StoringImages...

Saving and Displaying Images from the Server Folder and MS SQL Database
Displaying images from Server Folder and SQL Server 2000 Database Uploading Images to Server Folder and SQL SERVER 2000 DatabaseHighOnCodingWanna get high! ...

How to load, edit and save image with VB.Net, SQL.Server
Hi there. I'm having a serious problem getting something very simple to work. In my page I'm having ImageButton display picture in SQL. The problem starts when I want to edit picture (add line,pie on the picture) and save it. I use programing VB.Net Please help me. This link will help you edit the picture..... not sure abt how to put it back into the db !http://www.vbcity.com/forums/faq.asp?fid=9&cat=Graphics&#TID84337Regards, Narayana Rao Surapaneni Architect | Author | MCSD for .NET | MCSD | SCJP www.msdeveloper.info ...

Simple display image from Sql Server with a datalist and datasource control
Hello and thanks for your help in advance as I am struggling with something fairly easy but as a novice I am probably nor understanding how things work. I am trying to retrieve an image that I can succesfully upload in a SqlServer database in an asp.net page, I have read many many tutorials but I have not found something that matches with what this: I simply have a web form with a correcly configured sqlDataSource control and a datalist on which I have used an image control to bind to the image BLOB field in the database table, clearly this not work... I understand that the image control l...

Web resources about - How to save image in sql server and display that image in datagrid?? - asp.net.sql-datasource

Want to preview our new DataGrid for Xamarin.Forms?
tl;dr Zumero.DataGrid is a Xamarin.Forms control for displaying data in rows and columns. If you would be interested in testing and previewing ...

Mad King DataGrid
This post is about scrolling in WPF and the egocentric DataGrid control. I’ll give the project background but if all you’re interested in is ...

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 295 ...

Microsoft Silverlight - Wikipedia, the free encyclopedia
Microsoft Silverlight is an application framework for writing and running rich Internet applications , with features and purposes similar to ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Casaba Security » Products » X5s Testing Tool For Finding XSS Vulnerabilities
Security analysis, consulting, development and testing partners who understand your business strategy.

CodeGuru - Microsoft developers related ideas, articles, tips, tricks, comments, downloads, and so much ...
CodeGuru is where developers can come to share ideas, articles, questions, answers, tips, tricks, comments, downloads, and so much more related ...

Caliburn Micro: WPF, Silverlight, WP7 and WinRT/Metro made easy.
A small, yet powerful framework designed for WPF, Silverlight and WP7. It implements a variety of UI patterns for solving real-world problems. ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 11 Jul 2012

license-discuss@opensource.org: 11636: first draft of license proliferation committee report
FYI,the first draft report of the OSI's License Proliferation Committee.To join the OSI's license proliferation discuss email list, send anemail ...

Resources last updated: 1/15/2016 7:13:40 PM