1

I am trying to create a website that can let user to search images. I created a local database ( a folder with a few images) for image, and there are 3 columns for data: title, picURL and keyword.

At my default page, I set up a textbox and Search button. What I did is:

string query = "SELECT picURL FROM imagedatabase WHERE [keyword] = '" + keyword + "'";

[keyword] is one of the name of the column and the keyword is the one user types in the textbox.

So now if I find an image in the database, then I got its URL. But how can I display the image in .aspx? like are they any specific command or something I can do to display the image?

thanks


EDIT:

So I changed the code like this:

In my homepage.aspx, I added in this:

<asp:Image ID="Image1" runat="server" ImageUrl="Image1.ImageUrl" />

and in my homepage.aspx.cs, I wrote this:

  protected void btnImageSearch_Click(object sender, EventArgs e)
{
    ImageSearch();
}
private void ImageSearch()
{
    string ImageURL;
   ImageURL= Process.KeywordSearch(txtSearch.Text);
   Image1.ImageUrl = ImageURL;

}

and in my Process.cs, I wrote this:

public static string KeywordSearch(string keyword)
{
    string query = "SELECT imagepath FROM tbimage WHERE [title] = '" + keyword + "'";       

    return query;

}

After I wrote all these, I tried to debug. I typed in the keyword, but no image showed up. I know in Process.cs, query will get the URL in database (the URL is like C:\ ....) So Image1.ImageUrl should equal to that URL. but then I am wondering if

can this really get the Image1.ImageUrl? because no image showed up.

Hope somebody can help and thanks

1 Answer 1

3

for this you can use Image control of asp.net and set its ImageUrl property to your image url. Like this

<asp:Image ID="Image1" runat="server" />

and in CodeBehind

Image1.ImageUrl = query;

Do as follow

1 Save or move your images into a folder.
2 Add this folder into your solution or project.
3 Take image name only (not physical path) from your database.
4 Set ImageUrl property to virtual path.

Sign up to request clarification or add additional context in comments.

4 Comments

Hey I followed what you said and got a problem. I edited the post to give more information what problem I have. Thanks a lot
@Ric: remove ImageUrl="Image1.ImageUrl" that is wrong see my updated answer and then try and let me know.
one more thing you are using physical path but image control takes only virtual path.
ok so I took made string query = "SELECT picName FROM imagedatabase WHERE [keyword] = '" + keyword + "'"; but what is the meaning of virtual path?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.