{"id":234,"date":"2012-09-21T11:56:43","date_gmt":"2012-09-21T11:56:43","guid":{"rendered":"http:\/\/ntspl.co.in\/blog\/?p=234"},"modified":"2024-09-18T10:43:15","modified_gmt":"2024-09-18T10:43:15","slug":"insert-update-using-linq","status":"publish","type":"post","link":"https:\/\/www.ntspl.co.in\/blog\/insert-update-using-linq\/","title":{"rendered":"Insert Update Using LINQ"},"content":{"rendered":"<pre class=\"code-structure\"><code>\r\nsewakdbDataContext swdb = new sewakdbDataContext();\r\ntbl_AnnualReport tbannual = new tbl_AnnualReport();\r\n\r\ntry {\r\n\r\n\t#region Insert\/Update data\r\n\tif (hfid.Value != string.Empty)\t{\r\n\r\n\t\ttbannual = (from d in swdb.tbl_AnnualReports where d.AR_ID == Convert.ToInt32(hfid.Value) select d).FirstOrDefault();\r\n\r\n\t\tbtnSubmit.Text = \"Submit\";\r\n\r\n\t\tmsg = \"Updated Successfully\";\r\n\r\n\t} else {\r\n\r\n\t\tswdb.tbl_AnnualReports.InsertOnSubmit(tbannual);\r\n\r\n\t\tmsg = \"Inserted Successfully\";\r\n\r\n\t}\r\n\r\n\t#endregion\r\n\t#region Entity\r\n\ttbannual.AR_DATE =Convert.ToDateTime (txtARDate.Text.Trim());\r\n\ttbannual.AR_HEADLINE = txtHeadline.Text.Trim();\r\n\ttbannual.entry_date = DateTime.Now;\r\n\ttbannual.ARCHIVE_STATUS = false;\r\n\ttbannual.DELSTATUS = false;\r\n\tif (FileUpload1.HasFile)\r\n\t\ttbannual.AR_COVER_IMAGE = uploadPhoto(ref FileUpload1);\r\n\r\n\tif(FileUpload2.HasFile)\r\n\t\ttbannual.AR_FILE = uploadDocument(ref FileUpload2);\r\n\r\n\t#endregion\r\n\tlblerr.Text = msg;\r\n\tlblerr.ForeColor = System.Drawing.Color.Green;\r\n\tswdb.SubmitChanges();\r\n\t<span class=\"comment\">\/\/Reset<\/span>\r\n\r\n\treset();\r\n\r\n\t<span class=\"comment\">\/\/Fill gridview<\/span>\r\n\t_LoadGrid();\r\n\r\n} catch (Exception ex) {\r\n\r\n\tlblerr.Text = ex.ToString();\r\n\tlblerr.ForeColor = System.Drawing.Color.Red;\r\n\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>sewakdbDataContext swdb = new sewakdbDataContext(); tbl_AnnualReport tbannual = new tbl_AnnualReport(); try { #region Insert\/Update data if (hfid.Value != string.Empty) { tbannual = (from d in swdb.tbl_AnnualReports where d.AR_ID == Convert.ToInt32(hfid.Value) select d).FirstOrDefault(); btnSubmit.Text = &#8220;Submit&#8221;; msg = &#8220;Updated Successfully&#8221;; } else { swdb.tbl_AnnualReports.InsertOnSubmit(tbannual); msg = &#8220;Inserted Successfully&#8221;; } #endregion #region Entity tbannual.AR_DATE =Convert.ToDateTime (txtARDate.Text.Trim()); tbannual.AR_HEADLINE [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":1517,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[3],"tags":[183,354],"class_list":["post-234","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-dot-net","tag-insert-using-linq","tag-update-using-linq"],"acf":{"custom_meta_title":"Insert and Update Data using LINQ | NTSPL","meta_description":"Do you know how to insert and update data using LINQ? Read the blog and get the simple and easy code to insert & update data using LINQ.","meta_keyword":"insert data using linq, update data using linq","other_meta_tag":"<meta property=og:locale content=\"en-IN\" \/>\r\n<meta property=og:type content=\"website\" \/>\r\n<meta property=og:title content=\"Insert and Update Data using LINQ | NTSPL\"\/>\r\n<meta property=og:description content=\"Do you know how to insert and update data using LINQ? Read the blog and get the simple and easy code to insert & update data using LINQ.\"\/>\r\n<meta property=og:url content=\"https:\/\/www.ntspl.co.in\/blog\/insert-update-using-linq\"\/>\r\n<meta property=\"og:image\" content=\"https:\/\/www.ntspl.co.in\/blog\/wp-content\/uploads\/2012\/09\/insert-update-using-linq.jpg\"\/>\r\n<meta property=og:site_name content=NTSPL \/>\r\n<meta name=\"twitter:site\" content=\"@NTSPL\">\r\n<meta name=twitter:card content=\"summary\" \/>\r\n<meta name=twitter:description content=\"Do you know how to insert and update data using LINQ? Read the blog and get the simple and easy code to insert & update data using LINQ.\"\/>\r\n<meta name=twitter:title content=\"Insert and Update Data using LINQ | NTSPL\"\/>"},"_links":{"self":[{"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/posts\/234"}],"collection":[{"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/comments?post=234"}],"version-history":[{"count":4,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/posts\/234\/revisions"}],"predecessor-version":[{"id":10576,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/posts\/234\/revisions\/10576"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/media\/1517"}],"wp:attachment":[{"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/media?parent=234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/categories?post=234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ntspl.co.in\/blog\/wp-json\/wp\/v2\/tags?post=234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}