在下一页上显示数据库中的相同图像 [英] Display same image from database on the next page
问题描述
我正在一个我遇到问题的网站上工作,我是初学者所以请不要生我的气。我的问题是:我已将图像文件上传到数据库并同时在框中显示。现在我想要的是当我跳到下一页时,相同的图片会显示在那里的框中,所以我可以对它进行一些调整。
我做了什么远远是遵循一段代码,但没有成功它给出错误
I am working on a website where I am facing a problem, I am beginner so please don't get angry on me. My question is: I have uploaded an image file into database and displayed it in the box simultaneously. Now what I want is when I jump to next page the same picture will appear in the box there so I can do some resizing of it.
What I have done so far is following piece of code but no success it is giving the error
Must declare the scalar variable "@id"
我有谷歌的解决方案,但没有解决方案,我发现为我工作,任何帮助将不胜感激,谢谢提前
ASPX部分是:
I have google for solution but there is no solution I'd found that working for me, any help will be appreciated, thanks in advance
ASPX Part is:
<asp:Image ID="image" runat="server" ImageUrl='<%# Eval("image") %>' width="450" />
CS部分是:
CS Part is:
SqlConnection con = new SqlConnection("Data Source=Tim-PC\\SQLEXPRESS;Initial Catalog=AP_Data;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
SqlDataAdapter sda = new SqlDataAdapter("SELECT image FROM photo WHERE id=@id", con);
DataTable dt = new DataTable();
sda.Fill(dt);
GridView1.DataSource = dt;
DataBind();
}
推荐答案
1.错误是由SQL字符串中的错误生成的。你有一个参数@id,它在使用适配器中的SQL之前没有与一个值相关联。
2.错误的解决方案是创建一个SQL命令并在创建适配器之前设置@id param的值:
1.The error is generated by the error in your SQL string. You have a parameter "@id" that was not linked with a value before to use the SQL in adapter.
2.The solution for the error is to create a SQL command and to set the value for the @id param, before to create the adapter:
SqlCommand command = new SqlCommand(commandText, con);
command.Parameters.Add("@id", SqlDbType.Int);
command.Parameters["@id"].Value = imageID; //here must be the image ID!
SqlDataAdapter sda = new SqlDataAdapter(command); //Create the adapter based on the command!
//... your code...
3.从您对我的解决方案的评论中得出的第二个错误的答案是:您必须从您的页面更正您的代码,如下所示:
3.The answer to your 2nd error from your comment to my solution is: you have to correct your code from your page like below:
<asp:Image ID="image" runat="server" ImageUrl='<%# string.Format("image-size.aspx?id={0}", Eval("id"))%>' width="450" />
>
这篇关于在下一页上显示数据库中的相同图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!