Click here to Skip to main content
15,915,163 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hey i want to retreive photo from database where i stored the filename but image is saved in images folder inside the website

below is my code for register page where i have to upload a photo
protected void Button1_Click(object sender, EventArgs e)
{
int userid=1 ;
string pathname = "images/" +FileUpload1.PostedFile.FileName;
//string pathname = Path.GetFileName(FileUpload1.PostedFile.FileName);
//FileUpload1.SaveAs(Server.MapPath("image/" + pathname));
SqlCommand cmd = new SqlCommand("insertregister",con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@username", SqlDbType.VarChar, 50).Value = TextBox1.Text;
cmd.Parameters.Add("@password", SqlDbType.VarChar, 50).Value = TextBox2.Text;
cmd.Parameters.Add("@email", SqlDbType.VarChar, 50).Value = TextBox4.Text;
cmd.Parameters.Add("@createdate", SqlDbType.DateTime).Value = DateTime.Now;
cmd.Parameters.Add("@images", SqlDbType.VarChar,50).Value = (FileUpload1.PostedFile.FileName);
cmd.Connection = con;
con.Open();
userid = Convert.ToInt32(cmd.ExecuteScalar());
cmd.ExecuteNonQuery();
cmd.Dispose();
con.Close();
FileUpload1.SaveAs(Server.MapPath("~/images/" + FileUpload1.PostedFile));
//FileUpload1.SaveAs(Server.MapPath("image/"+pathname));
string message = string.Empty;
switch (userid)
{
case -1:
message = "username already exist";
break;
case -2 :
message = "email already used";
break;
default:
message="registered seccussfully"+ userid.ToString();
break;
}
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
TextBox1.Text = string.Empty;
TextBox2.Text = string.Empty;
TextBox3.Text = string.Empty;
TextBox4.Text = string.Empty;
TextBox1.Focus();

}


i have used template field and then eval but not displaying photo
Posted
Updated 27-Jul-14 19:58pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900