Advertisement

03.18.2008 at 07:35AM PDT, ID: 23250331
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Get multiple images from server asp.net, c#, sql

Tags: c#, asp.net, sql
Hi I Currently have a website that stores information like images and description of it to a database.
I can reterieve the image that is uploaded but what i want to do is reterieve multiple images from the database.
For example Main Image and the image 2, 3, 4. then when you click on Image 1 it replaces the main Image.
I would like a tutorial on this please help.
Also I have attached an image to get a better Idea but instead of where it says image 1, 2, 3 it would be images. And onclicking them it would be displayed in the main image


Thanks,

R8VI
Attachments:
 
Example
Example
 
Start your free trial to view this solution
Question Stats
Zone: Microsoft
Question Asked By: R8VI
Solution Provided By: renjurdevan
Participating Experts: 1
Solution Grade: A
Views: 391
Translate:
Loading Advertisement...
03.18.2008 at 08:13AM PDT, ID: 21151894

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.18.2008 at 08:19AM PDT, ID: 21151981

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.18.2008 at 09:31AM PDT, ID: 21152840

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.18.2008 at 09:51AM PDT, ID: 21153109

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.18.2008 at 08:13AM PDT, ID: 21151894

Rank: Guru

Please go through the code

Regards
Renju
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
The upload aspx page 
<%@ Page Language="c#" Src="UploadImage.aspx.cs" Inherits="DBImages.UploadImage"
    MasterPageFile="~/YourAgent2.master" AutoEventWireup="true" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <h3>
        Upload your Image</h3>
    Enter A Friendly Name<input type="text" id="txtImgName" runat="server" />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required"
        ControlToValidate="txtImgName"></asp:RequiredFieldValidator>
    <br />
    Select File To Upload:
    <input id="UploadFile" type="file" runat="server" />
    <asp:Button ID="UploadBtn" Text="Upload Me!" OnClick="UploadBtn_Click" runat="server">
    </asp:Button>
    <br />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    <br />
    <br />
    <br />
</asp:Content>
 
Code behind 
 
 public void UploadBtn_Click(object sender, System.EventArgs e)
        {
            if (Page.IsValid) //save the image
            {
                Stream imgStream = UploadFile.PostedFile.InputStream;
                int imgLen = UploadFile.PostedFile.ContentLength;
                string img_contenttype = UploadFile.PostedFile.ContentType;
                string img_name = txtImgName.Value;
                byte[] img_data = new byte[imgLen];
                int n = imgStream.Read(img_data, 0, imgLen);
 
                String idis = Request.QueryString["id"];
                int business_id = System.Convert.ToInt32(idis);
 
                int RowsAffected = SaveToDB(img_name, img_data, img_contenttype, business_id);
                if (RowsAffected > 0)
                {
                    TextBox TextBox2 = new TextBox();
                    TextBox2.Text = "The Image was Saved";
                    /*Response.Write("<BR>The Image was saved");*/
                }
                else
                {
                    Response.Write("<BR>An error occurred uploading the image");
                }
 
            }
        }
 
 
        private int SaveToDB(string img_name, byte[] img_data, string img_contenttype, int business_id)
        {
            //use the web.config to store the connection string
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["tempdbConnectionString"].ConnectionString);
            SqlCommand command = new SqlCommand("INSERT INTO Image (img_name, img_data, img_contenttype, business_id) VALUES ( @img_name, @img_data,@img_contenttype,@business_id)", connection);
 
            SqlParameter param0 = new SqlParameter("@img_name", SqlDbType.VarChar, 50);
            param0.Value = img_name;
            command.Parameters.Add(param0);
 
            SqlParameter param1 = new SqlParameter("@img_data", SqlDbType.Image);
            param1.Value = img_data;
            command.Parameters.Add(param1);
 
            SqlParameter param2 = new SqlParameter("@img_contenttype", SqlDbType.VarChar, 50);
            param2.Value = img_contenttype;
            command.Parameters.Add(param2);
 
            SqlParameter param3 = new SqlParameter("@business_id", SqlDbType.Int, 4);
            param3.Value = business_id;
            command.Parameters.Add(param3);
 
            connection.Open();
            int numRowsAffected = command.ExecuteNonQuery();
            connection.Close();
 
            return numRowsAffected;
        }
    }
 
GetImage.aspx
<%@ Page Language="C#" MasterPageFile="~/YourAgent2.master" AutoEventWireup="true" CodeFile="GetImage.aspx.cs" Inherits="GetImage" Title="Untitled Page" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
</asp:Content>
 
CODE BEHIND 
 
 protected void Page_Load(object sender, EventArgs e)
    {
        System.Data.SqlClient.SqlDataReader Reader = null;
        string ImageIdentity = Request.QueryString["id"].ToString();
        SqlConnection sqlConnection = new SqlConnection(@"Data Source=ITDEV02\sqlexpress;Initial Catalog=tempdb;Integrated Security=True;");
        sqlConnection.Open();
        SqlCommand sqlCommand = new SqlCommand("Select img_data,img_contenttype from Image where business_id=" + ImageIdentity, sqlConnection);
        Reader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
        Reader.Read();
        Response.Clear();
        Response.ContentType = Reader["img_contenttype"].ToString();
 
        /// Read the database image into a byte array
        byte[] byteArray = (byte[])Reader["img_data"];
        if (Request.QueryString["ThumbNail"] == null)
        {
            /// Move the byte array into a memory stream. This is an intermediate step to convert the byte array into
            /// a system.Drawing.Image
            System.IO.MemoryStream mstream = new System.IO.MemoryStream(byteArray, 0, byteArray.Length);
            /// The System.Drawing image allows us to retrieve properties of the image (height width for example)
            System.Drawing.Image dbImage = System.Drawing.Image.FromStream(new System.IO.MemoryStream(byteArray));
            /// Create a new image - a thumbnail by changing the height and width
            System.Drawing.Image thumbnailImage = dbImage.GetThumbnailImage(100, 100, null, new System.IntPtr());
            /// Overwrite the memory stream with the Thumbnail Image getting the image format from the database image
            thumbnailImage.Save(mstream, dbImage.RawFormat);
            /// Convert the memory stream into a byte array
            Byte[] thumbnailByteArray = new Byte[mstream.Length];
            mstream.Position = 0;
            mstream.Read(thumbnailByteArray, 0, Convert.ToInt32(mstream.Length));
            Response.BinaryWrite(thumbnailByteArray);
        }
        else
        {
            Response.BinaryWrite(byteArray);
        }
        //      Response.BinaryWrite(thumbnailByteArray);
 
    }
 
page called BUY.aspx to display in a datagrid 
<%@ Page Language="C#" MasterPageFile="~/YourAgent2.master" AutoEventWireup="true"
    CodeFile="Buy.aspx.cs" Inherits="Buy" Title="Untitled Page" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="False">
        <Columns>
            <asp:BoundColumn DataField="ImageIdentity" HeaderText="ImageIdentity" Visible="False">
            </asp:BoundColumn>
            <asp:BoundColumn DataField="img_name" HeaderText="Image Name"></asp:BoundColumn>
            <asp:BoundColumn DataField="img_contenttype" HeaderText="Image Type"></asp:BoundColumn>
            <asp:TemplateColumn HeaderText="Image">
                <ItemTemplate>
                    <a href='<%# "getImage.aspx?ThumbNail=\"N\"&ID=" + DataBinder.Eval(Container.DataItem, 
                   "ImageIdentity")  %>'>
                        <img runat="server" src='<%# "getImage.aspx?ID=" + DataBinder.Eval(Container.DataItem, 
                   "ImageIdentity")%>' id="Img1" /></a>
                </ItemTemplate>
            </asp:TemplateColumn>
        </Columns>
    </asp:DataGrid>
</asp:Content>
 
CODE BEHIND 
 
 private void Page_Load(object sender, System.EventArgs e)
    {
        System.Data.SqlClient.SqlDataReader Reader = null;
        SqlConnection SqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["tempdbConnectionString"].ConnectionString);
        SqlConnection.Open();
        SqlCommand sqlCommand = new SqlCommand("GetImages", SqlConnection);
        sqlCommand.CommandType = CommandType.StoredProcedure;
        Reader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
        DataGrid1.DataSource = Reader;
        DataGrid1.DataBind();
    }
Open in New Window
Accepted Solution
 
03.18.2008 at 08:19AM PDT, ID: 21151981

Rank: Guru

Basically get images from database as bytes array and write it into a page like

Response.BinaryWrite(byteArray);

Then
in Gridview
<asp:TemplateColumn HeaderText="Image">
                <ItemTemplate>
                    <a href='<%# "getImage.aspx?ThumbNail=\"N\"&ID=" + DataBinder.Eval(Container.DataItem,
                   "ImageIdentity")  %>'>
                        <img runat="server" src='<%# "getImage.aspx?ID=" + DataBinder.Eval(Container.DataItem,
                   "ImageIdentity")%>' id="Img1" /></a>
                </ItemTemplate>
            </asp:TemplateColumn>


here you are setting image src as  getImage.aspx with few query string !! getImage.aspx is the page where you write your inage from database !
like
Response.BinaryWrite(byteArray);
And the query string will pass appropriate values!
GridView or DataGrid belongs to your page!

Regards
Renju
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
In getImage.aspx
 
protected void Page_Load(object sender, EventArgs e)
    {
        System.Data.SqlClient.SqlDataReader Reader = null;
        string ImageIdentity = Request.QueryString["id"].ToString();
        SqlConnection sqlConnection = new SqlConnection(@"Data Source=ITDEV02\sqlexpress;Initial Catalog=tempdb;Integrated Security=True;");
        sqlConnection.Open();
        SqlCommand sqlCommand = new SqlCommand("Select img_data,img_contenttype from Image where business_id=" + ImageIdentity, sqlConnection);
        Reader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
        Reader.Read();
        Response.Clear();
        Response.ContentType = Reader["img_contenttype"].ToString();
 
        /// Read the database image into a byte array
        byte[] byteArray = (byte[])Reader["img_data"];
        if (Request.QueryString["ThumbNail"] == null)
        {
            /// Move the byte array into a memory stream. This is an intermediate step to convert the byte array into
            /// a system.Drawing.Image
            System.IO.MemoryStream mstream = new System.IO.MemoryStream(byteArray, 0, byteArray.Length);
            /// The System.Drawing image allows us to retrieve properties of the image (height width for example)
            System.Drawing.Image dbImage = System.Drawing.Image.FromStream(new System.IO.MemoryStream(byteArray));
            /// Create a new image - a thumbnail by changing the height and width
            System.Drawing.Image thumbnailImage = dbImage.GetThumbnailImage(100, 100, null, new System.IntPtr());
            /// Overwrite the memory stream with the Thumbnail Image getting the image format from the database image
            thumbnailImage.Save(mstream, dbImage.RawFormat);
            /// Convert the memory stream into a byte array
            Byte[] thumbnailByteArray = new Byte[mstream.Length];
            mstream.Position = 0;
            mstream.Read(thumbnailByteArray, 0, Convert.ToInt32(mstream.Length));
            Response.BinaryWrite(thumbnailByteArray);
        }
        else
        {
            Response.BinaryWrite(byteArray);
        }
        //      Response.BinaryWrite(thumbnailByteArray);
 
    }
 
Open in New Window
 
03.18.2008 at 09:31AM PDT, ID: 21152840
Hi Wud i do that for evey image ?
 
03.18.2008 at 09:51AM PDT, ID: 21153109

Rank: Guru

in a gridview! it will call page for each and evey row!
in grid you show Thumbnail! once click on the thumbnail show Big image!

Regards
Renju
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628