Retriving similar images from database?

Posted by Anilkumar431 under ASP.NET on 2/1/2013 | Points: 10 | Views : 690 | Status : [Member] | Replies : 2
hi all,
i have one app which contains one textbox if the user enter one image name in that textbox i need to display similar to that particular image.
please give me solution for this.
thanx in advance..




Responses

Posted by: Satyapriyanayak on: 2/1/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Image_name._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lb1" runat="server" Font-Bold="True" ForeColor="#FF3300"></asp:Label><br />
<asp:TextBox ID="TextBox_image_name" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Show image" />
</div>

</form>
</body>
</html>



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Image_name
{
public partial class _Default : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;

protected void Button1_Click(object sender, EventArgs e)
{
object obj = null;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select count(*) from imagetest where imagename=@imagename";
com = new SqlCommand(str, con);
com.CommandType = CommandType.Text;
Session["imagename"] = TextBox_image_name.Text;
com.Parameters.AddWithValue("@imagename", Session["imagename"]);
obj = com.ExecuteScalar();
if ((int)(obj) != 0)
{
Response.Redirect("image.aspx");
}
else
{
lb1.Text = "Invalid imagename";
clear();
}
con.Close();
}
private void clear()
{
TextBox_image_name.Text = "";

}
}
}


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="image.aspx.cs" Inherits="Image_name.image" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="#CC3300" ForeColor="Black" ShowHeader="False" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<img alt ="" src ='images/<%#Eval("image") %>' height="50px" width="50px"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Image_name
{
public partial class image : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlDataAdapter sqlda;
DataTable dt;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid();
}
}
private void bindgrid()
{
string imagename = (string)Session["imagename"];
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "select image from imagetest where imagename='" + imagename + "'";
sqlda = new SqlDataAdapter(str, con);
dt = new DataTable();
sqlda.Fill(dt);
sqlda.Dispose();
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
}
}


If this post helps you mark it as answer
Thanks

Anilkumar431, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 2/1/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
http://www.dotnetfunda.com/blogs/satyapriyanayak/4098/display-image-in-webpage-when-we-enter-the-name-of-the-image

If this post helps you mark it as answer
Thanks

Anilkumar431, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response