hi, I'm doing a Real Estate Website where I have an upload image web form which saves the image paths of the images into my database. I am trying to view details of the property in another web form, but I can't retrieve the images, only the data is being retrieved.
The following is the code I used to save the details of the property:
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connString);
con.Open();
SqlCommand storeimage = new SqlCommand("INSERT INTO Properties "
+ "(RefNo, Price, Location, Type, NoOfBedrooms, Description, Basis, Image_Path1, Image_Path2, Image_Path3, Image_Path4, Image_Path5, Image_Path6) "
+ " values ('" + Label1.Text + "','" + Price.Text + "' , '" + Location.SelectedItem.Value + "','" + Type.SelectedItem.Value + "','" + Bedrooms.SelectedItem.Value + "','" + Description.Text + "','" + Basis.SelectedItem.Value + "','" + Imageupload.FileName + "','" + Imageupload1.FileName + "','" + Imageupload2.FileName + "','" + Imageupload3.FileName + "','" + Imageupload4.FileName + "','" + Imageupload5.FileName + "')", con);
string strPath = Server.MapPath("Properties");
string strPath1 = Server.MapPath("Properties");
string strPath2 = Server.MapPath("Properties");
if (Imageupload.HasFile)
{
Imageupload.SaveAs (strPath + "\\" + Imageupload.FileName);
}
if (Imageupload1.HasFile)
{
Imageupload1.SaveAs(strPath1 + "\\" + Imageupload1.FileName);
}
if (Imageupload2.HasFile)
{
Imageupload2.SaveAs(strPath2 + "\\" + Imageupload2.FileName);
}
if (Imageupload3.HasFile)
{
Imageupload3.SaveAs(strPath2 + "\\" + Imageupload3.FileName);
}
if (Imageupload4.HasFile)
{
Imageupload4.SaveAs(strPath2 + "\\" + Imageupload4.FileName);
}
if (Imageupload5.HasFile)
{
Imageupload5.SaveAs(strPath2 + "\\" + Imageupload5.FileName);
}
storeimage.ExecuteNonQuery();
con.Close();
The following is the aspx code which shows the form and the C# code I am using to bind text boxes with details.
ASPX:
<div id=image1>
<asp:Image ID="img1" runat="server" Height="120px" Width="100px" />
</div>
<div id=image2>
<asp:Image ID="img2" runat="server" Height="120px" Width="100px" />
</div>
<div id=image3>
<asp:Image ID="img3" runat="server" Width="100px" Height="120px"/>
</div>
<div id=image4>
<asp:Image ID="img4" runat="server" Height="120px" Width="100px" />
</div>
<div id=image5>
<asp:Image ID="img5" runat="server" Height="120px" Width="100px" />
</div>
<div id=text>
<asp:Label ID=type runat=server Text="Type:"></asp:Label>
<br />
<asp:Label ID=refno runat=server Text="Reference Number:"></asp:Label>
<br />
<asp:Label ID=noofbedrooms runat=server Text="Bedrooms:"></asp:Label>
<br />
<asp:Label ID=price runat=server Text="Price:"></asp:Label>
<br />
<asp:Label ID=locality runat=server Text="Locality:"></asp:Label>
<br />
<asp:Label ID=description runat=server Text="Description:"></asp:Label>
<br />
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!(IsPostBack))
{
string s = Request.QueryString["RefNo"].ToString();
string select = "SELECT RefNo, Price, Location, Type, NoOfBedrooms, Description, Image_Path1, Image_Path2, Image_Path3, Image_Path4, Image_Path5 FROM Properties WHERE RefNo = " + s + "";
SqlConnection con = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand(select, con);
SqlDataReader dr;
con.Open();
dr = cmd.ExecuteReader();
while (dr.Read())
{
reference.Text = dr[0].ToString();
price1.Text = dr[1].ToString();
loc.Text = dr[2].ToString();
type1.Text = dr[3].ToString();
bedrooms.Text = dr[4].ToString();
desc.Text = dr[5].ToString();
}
con.Close();
}
Can you please help me with retrieving the images also?
Thanks in advance