protected void btnSave_ServerClick(object sender, EventArgs e) { try { string GalleryID; bool retVal = true; if (filenm.Value != "") { string ID = SaveImage(out GalleryID); GalleryViewModel _galleryViewModel = new GalleryViewModel(); GalleryModel _galleryModel = new GalleryModel(); _galleryModel.GalleryID = GalleryID; _galleryModel.GalleryImagePath = ID; _galleryModel.Description = ""; retVal = _galleryViewModel.SaveGalleryImage(_galleryModel); BindDataList(); if (retVal == false) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Event Gallery", "<script type='text/javascript'>ConfirmMsg('Unexpected error occured.Plese refresh the page and try again!.','Event Gallery');</script>", false); } else if (retVal == true) { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Event Gallery", "<script type='text/javascript'>EnabelBtn();</script>", false); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Event Gallery", "<script type='text/javascript'>ConfirmMsg('Gallery Image Saved Sucessfully.','Event Gallery');</script>", false); } } else { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Event Gallery", "<script type='text/javascript'>ConfirmMsg('Select Image for gallery.','Event Gallery');</script>", false); } } catch (Exception ex) { ErrHandler.WriteError(ex.Message); System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(@"<script language='javascript'>"); sb.Append(@"alert('Error : " + ex.Message + "')"); sb.Append(@"</script>"); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", sb.ToString(), false); } }
public bool SaveGalleryImage(GalleryModel _galleryModel) { try { using (SqlConnection conn = new SqlConnection(ConnString)) { using (SqlCommand cmd = new SqlCommand("INSERT INTO GalleryImage VALUES('" + _galleryModel.GalleryID + "','" + _galleryModel.GalleryImagePath + "','" + _galleryModel.Description + "')", conn)) { conn.Open(); cmd.ExecuteNonQuery(); return true; } } } catch (Exception ex) { throw ex; } }