Just Copy & Paste This code on Your Page .. Defiantly it will Run
if (ddlCategoryType.SelectedItem.Text != "--Select--")
{
string strimage2 = "NoImage.jpg";
string strimage = "NoImage.jpg";
if (FileUpload1.PostedFile.ContentLength != 0)
{
strimage= @"~\ProductImage\" + FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath(strimage));
}
if (FileUpload2.PostedFile.ContentLength != 0 )
{
strimage2 = @"~\ProductImage\" + FileUpload2.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath(strimage2));
}
if(FileUpload1.HasFile || FileUpload2.HasFile)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
String strInsert = "insert into ProductDetailsTable1(CategoriesType,Title,Description,State,City,ContactPhoto,ContactSPhoto,Price,ContactName,ContactEmail,ContactMobile) values('" + ddllist.Text + "','" + txtTitle.Text + "','" + txtDescription.Text + "','" + ddlState.SelectedItem.Text + "','" + ddlCity.SelectedItem.Text + "','" + strimage + "','" + strimage2 + "','" + txtPrice.Text + "','" + txtContactName.Text + "','" + txtContactEmail.Text + "','" + txtContactMobile.Text + "',)";
SqlCommand cmd = new SqlCommand(strInsert, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Posted Successfully')", true);
}
catch (SqlException ex)
{
string errorMessage = "Error in entering competition";
errorMessage += ex.Message;
throw new Exception(errorMessage);
}
finally
{
con.Close();
}
}
else
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
String strInsert = "insert into ProductDetailsTable1(CategoriesType,Title,Description,State,City,ContactPhoto,ContactSPhoto,Price,ContactName,ContactEmail,ContactMobile) values('" + ddllist.Text + "','" + txtTitle.Text + "','" + txtDescription.Text + "','" + ddlState.SelectedItem.Text + "','" + ddlCity.SelectedItem.Text + "','" + strimage + "','" + strimage2 + "','" + txtPrice.Text + "','" + txtContactName.Text + "','" + txtContactEmail.Text + "','" + txtContactMobile.Text + "')";
SqlCommand cmd = new SqlCommand(strInsert, con);
try
{
con.Open();
cmd.ExecuteNonQuery();
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Posted Successfully')", true);
}
catch (SqlException ex)
{
string errorMessage = "Error in entering competition";
errorMessage += ex.Message;
throw new Exception(errorMessage);
}
finally
{
con.Close();
}
}
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Select CategoryType')", true);
}