Click here to Skip to main content
15,891,745 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void SaveRecords_Click(object sender, EventArgs e)
{
for (int index = 0; index < Repeater1.Items.Count; index++)
{

Label lblSno = Repeater1.Items[index].FindControl("lblSno") as Label;
Label lblItemName = Repeater1.Items[index].FindControl("lblItemName") as Label;
Label lblItemQuantity = Repeater1.Items[index].FindControl("lblItemQuantity") as Label;
Label lblItemPrice = Repeater1.Items[index].FindControl("lblItemPrice") as Label;
Label lblItemTotalPrice = Repeater1.Items[index].FindControl("lblItemTotalPrice") as Label;
string FileName = Path.GetFileName(ImageUpload.PostedFile.FileName);
FileName = Guid.NewGuid().ToString();
String strConnString = ("Data Source=.;Initial Catalog=PRODUCT;Integrated Security=True");
SqlConnection con = new SqlConnection(strConnString);
string strQuery = "insert into tbl_Product (Sno,ItemName,ItemImage,ItemQuantity,ItemPrice,Total)values('" + lblSno.Text + "','" + lblItemName.Text + "','" + FileName + "','" + lblItemQuantity.Text + "','" + lblItemPrice.Text + "','" + lblItemTotalPrice.Text + "')";
SqlCommand cmd = new SqlCommand(strQuery, con);
con.Open();
cmd.ExecuteNonQuery();
Response.Write("<script>alert('Data Successfully Saved');</script>");


}
}
THIS SAVE ALL THE RECORD BUT THE IMAGE COLUMN SHOWN THERE EMPTY ANY HAVA ANY IDEA TO SOLVE
yOUR SINSER mIAN sAHIB jaN
Posted
Comments
Tom Marvolo Riddle 3-Apr-14 2:00am    
Remove this line
FileName = Guid.NewGuid().ToString();
and try
Mian Sahib Jan 3-Apr-14 2:08am    
I REMOVED THIS LINE BUT NOT YET WORK THIS COLUMN SHOWN IN DATABASE ARE EMPTY
Tom Marvolo Riddle 3-Apr-14 2:15am    
Your code looks correct.

(ImageUpload.PostedFile.FileName);
Does the control id is correct?
Mian Sahib Jan 3-Apr-14 3:28am    
yes this is correct dear!

1 solution

You are saving the filename in database, but you are not creating any image file on server with GUID as name.
I think you should save the image as [Guid].[bmp|png|jpg] (the image extension depends on your requirement) on server within a folder named ProductImages, and then use this url eg. "~/ProductImages/[GUID].png" as your FileName value.
 
Share this answer
 
v4

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