{"id":4578,"date":"2023-02-20T12:21:03","date_gmt":"2023-02-20T12:21:03","guid":{"rendered":"https:\/\/isophal.com\/?p=4578"},"modified":"2023-02-20T12:21:06","modified_gmt":"2023-02-20T12:21:06","slug":"ado-net-mvc-example","status":"publish","type":"post","link":"https:\/\/isophal.com\/news\/2023\/02\/20\/4578.html\/","title":{"rendered":"ADO.NET MVC Example"},"content":{"rendered":"\n<p>MVC (Model View Controller) is a web application design pattern that is widely used in application development. Here, we are creating an MVC application that connects to the SQL Server with the help of ADO.NET framework.<\/p>\n\n\n\n<p>This application contains a Model, a View and a Controller file. Following are the source codes of the application.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Model<\/h3>\n\n\n\n<p><strong>\/\/ Student.cs<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>using<\/strong>&nbsp;System;&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>using<\/strong>&nbsp;System.ComponentModel.DataAnnotations;&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>namespace<\/strong>&nbsp;Ado.NetMvcApplication.Models&nbsp;&nbsp;<\/li>\n\n\n\n<li>{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>class<\/strong>&nbsp;Student&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>int<\/strong>&nbsp;ID&nbsp;{&nbsp;<strong>get<\/strong>;&nbsp;<strong>set<\/strong>;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;&#8212;&nbsp;Validating&nbsp;Student&nbsp;Name&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Required(ErrorMessage&nbsp;=&nbsp;&#8220;Name&nbsp;is&nbsp;required&#8221;)]&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[MaxLength(12)]&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>string<\/strong>&nbsp;Name&nbsp;{&nbsp;<strong>get<\/strong>;&nbsp;<strong>set<\/strong>;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;&#8212;&nbsp;Validating&nbsp;Email&nbsp;Address&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Required(ErrorMessage&nbsp;=&nbsp;&#8220;Email&nbsp;is&nbsp;required&#8221;)]&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[EmailAddress(ErrorMessage&nbsp;=&nbsp;&#8220;Invalid&nbsp;Email&nbsp;Address&#8221;)]&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>string<\/strong>&nbsp;Email&nbsp;{&nbsp;<strong>get<\/strong>;&nbsp;<strong>set<\/strong>;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;&#8212;&nbsp;Validating&nbsp;Contact&nbsp;Number&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[Required(ErrorMessage&nbsp;=&nbsp;&#8220;Contact&nbsp;is&nbsp;required&#8221;)]&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[DataType(DataType.PhoneNumber)]&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[RegularExpression(@&#8221;^\\(?([0-9]{3})\\)?[-.&nbsp;]?([0-9]{3})[-.&nbsp;]?([0-9]{4})$&#8221;,&nbsp;ErrorMessage&nbsp;=&nbsp;&#8220;Not&nbsp;a&nbsp;valid&nbsp;Phone&nbsp;number&#8221;)]&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>string<\/strong>&nbsp;Contact&nbsp;{&nbsp;<strong>get<\/strong>;&nbsp;<strong>set<\/strong>;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;&nbsp;<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">View<\/h3>\n\n\n\n<p><strong>\/\/ Index.cshtml<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li>@model&nbsp;Ado.NetMvcApplication.Models.Student&nbsp;&nbsp;<\/li>\n\n\n\n<li>@{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;ViewBag.Title&nbsp;=&nbsp;&#8220;Index&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>&lt;<\/strong><strong>h2<\/strong><strong>&gt;<\/strong>Index<strong>&lt;\/<\/strong><strong>h2<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>@using&nbsp;(Html.BeginForm(&#8220;Save&#8221;,&nbsp;&#8220;Students&#8221;))&nbsp;&nbsp;<\/li>\n\n\n\n<li>{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;@Html.AntiForgeryToken()&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;<\/strong><strong>div<\/strong>&nbsp;class=&#8221;form-horizontal&#8221;<strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;<\/strong><strong>h4<\/strong><strong>&gt;<\/strong>Student<strong>&lt;\/<\/strong><strong>h4<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;<\/strong><strong>hr<\/strong>&nbsp;<strong>\/&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.ValidationSummary(true,&nbsp;&#8220;&#8221;,&nbsp;new&nbsp;{&nbsp;@class&nbsp;=&nbsp;&#8220;text-danger&#8221;&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;<\/strong><strong>div<\/strong>&nbsp;class=&#8221;form-group&#8221;<strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.LabelFor(model&nbsp;=<strong>&gt;<\/strong>&nbsp;model.Name,&nbsp;htmlAttributes:&nbsp;new&nbsp;{&nbsp;@class&nbsp;=&nbsp;&#8220;control-label&nbsp;col-md-2&#8221;&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;<\/strong><strong>div<\/strong>&nbsp;class=&#8221;col-md-10&#8243;<strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.EditorFor(model&nbsp;=<strong>&gt;<\/strong>&nbsp;model.Name,&nbsp;new&nbsp;{&nbsp;htmlAttributes&nbsp;=&nbsp;new&nbsp;{&nbsp;@class&nbsp;=&nbsp;&#8220;form-control&#8221;&nbsp;}&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.ValidationMessageFor(model&nbsp;=<strong>&gt;<\/strong>&nbsp;model.Name,&nbsp;&#8220;&#8221;,&nbsp;new&nbsp;{&nbsp;@class&nbsp;=&nbsp;&#8220;text-danger&#8221;&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;\/<\/strong><strong>div<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;\/<\/strong><strong>div<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;<\/strong><strong>div<\/strong>&nbsp;class=&#8221;form-group&#8221;<strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.LabelFor(model&nbsp;=<strong>&gt;<\/strong>&nbsp;model.Email,&nbsp;htmlAttributes:&nbsp;new&nbsp;{&nbsp;@class&nbsp;=&nbsp;&#8220;control-label&nbsp;col-md-2&#8221;&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;<\/strong><strong>div<\/strong>&nbsp;class=&#8221;col-md-10&#8243;<strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.EditorFor(model&nbsp;=<strong>&gt;<\/strong>&nbsp;model.Email,&nbsp;new&nbsp;{&nbsp;htmlAttributes&nbsp;=&nbsp;new&nbsp;{&nbsp;@class&nbsp;=&nbsp;&#8220;form-control&#8221;&nbsp;}&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.ValidationMessageFor(model&nbsp;=<strong>&gt;<\/strong>&nbsp;model.Email,&nbsp;&#8220;&#8221;,&nbsp;new&nbsp;{&nbsp;@class&nbsp;=&nbsp;&#8220;text-danger&#8221;&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;\/<\/strong><strong>div<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;\/<\/strong><strong>div<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;<\/strong><strong>div<\/strong>&nbsp;class=&#8221;form-group&#8221;<strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.LabelFor(model&nbsp;=<strong>&gt;<\/strong>&nbsp;model.Contact,&nbsp;htmlAttributes:&nbsp;new&nbsp;{&nbsp;@class&nbsp;=&nbsp;&#8220;control-label&nbsp;col-md-2&#8221;&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;<\/strong><strong>div<\/strong>&nbsp;class=&#8221;col-md-10&#8243;<strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.EditorFor(model&nbsp;=<strong>&gt;<\/strong>&nbsp;model.Contact,&nbsp;new&nbsp;{&nbsp;htmlAttributes&nbsp;=&nbsp;new&nbsp;{&nbsp;@class&nbsp;=&nbsp;&#8220;form-control&#8221;&nbsp;}&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.ValidationMessageFor(model&nbsp;=<strong>&gt;<\/strong>&nbsp;model.Contact,&nbsp;&#8220;&#8221;,&nbsp;new&nbsp;{&nbsp;@class&nbsp;=&nbsp;&#8220;text-danger&#8221;&nbsp;})&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;\/<\/strong><strong>div<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;\/<\/strong><strong>div<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;<\/strong><strong>div<\/strong>&nbsp;class=&#8221;form-group&#8221;<strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;<\/strong><strong>div<\/strong>&nbsp;class=&#8221;col-md-offset-2&nbsp;col-md-10&#8243;<strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;<\/strong><strong>input<\/strong>&nbsp;type=&#8221;submit&#8221;&nbsp;value=&#8221;Create&#8221;&nbsp;class=&#8221;btn&nbsp;btn-default&#8221;&nbsp;<strong>\/&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;\/<\/strong><strong>div<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;\/<\/strong><strong>div<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>&lt;\/<\/strong><strong>div<\/strong><strong>&gt;<\/strong>&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;&nbsp;<\/li>\n\n\n\n<li>@section&nbsp;Scripts&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;@Scripts.Render(&#8220;~\/bundles\/jqueryval&#8221;)&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;&nbsp;<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Controller<\/h3>\n\n\n\n<p><strong>\/\/ StudentsController.cs<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\" start=\"1\">\n<li><strong>using<\/strong>&nbsp;System.Web.Mvc;&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>using<\/strong>&nbsp;Ado.NetMvcApplication.Models;&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>using<\/strong>&nbsp;System.Data.SqlClient;&nbsp;&nbsp;<\/li>\n\n\n\n<li><strong>namespace<\/strong>&nbsp;Ado.NetMvcApplication.Controllers&nbsp;&nbsp;<\/li>\n\n\n\n<li>{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;<strong>class<\/strong>&nbsp;StudentsController&nbsp;:&nbsp;Controller&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;GET:&nbsp;Students&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;ActionResult&nbsp;Index()&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>return<\/strong>&nbsp;View();&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[HttpPost]&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>public<\/strong>&nbsp;ContentResult&nbsp;Save(Student&nbsp;student)&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>string<\/strong>&nbsp;status&nbsp;=&nbsp;&#8220;&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Creating&nbsp;Connection&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>using<\/strong>&nbsp;(SqlConnection&nbsp;con&nbsp;=&nbsp;<strong>new<\/strong>&nbsp;SqlConnection(&#8220;data&nbsp;source=.;&nbsp;database=student;&nbsp;integrated&nbsp;security=SSPI&#8221;))&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Insert&nbsp;query&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>string<\/strong>&nbsp;query&nbsp;=&nbsp;&#8220;INSERT&nbsp;INTO&nbsp;student(name,email,contact)&nbsp;VALUES(@name,&nbsp;@email,&nbsp;@contact)&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>using<\/strong>&nbsp;(SqlCommand&nbsp;cmd&nbsp;=&nbsp;<strong>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\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd.Parameters.AddWithValue(&#8220;@email&#8221;,&nbsp;student.Email);&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd.Parameters.AddWithValue(&#8220;@contact&#8221;,&nbsp;student.Contact);&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Executing&nbsp;insert&nbsp;query&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;=&nbsp;(cmd.ExecuteNonQuery()&nbsp;&gt;=&nbsp;1)&nbsp;?&nbsp;&nbsp;&#8220;Record&nbsp;is&nbsp;saved&nbsp;Successfully!&#8221;&nbsp;:&nbsp;&#8220;Record&nbsp;is&nbsp;not&nbsp;saved&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status&nbsp;+=&nbsp;&#8220;&lt;br\/&gt;&#8221;;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Executing&nbsp;select&nbsp;command&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>using<\/strong>&nbsp;(SqlCommand&nbsp;cmd&nbsp;=&nbsp;<strong>new<\/strong>&nbsp;SqlCommand(&#8220;select&nbsp;*&nbsp;from&nbsp;student&#8221;))&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cmd.Connection&nbsp;=&nbsp;con;&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/&nbsp;Retrieving&nbsp;Record&nbsp;from&nbsp;datasource&nbsp;&nbsp;<\/li>\n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Contact:&lt;\/b&gt;&nbsp;&#8220;+sdr[&#8220;contact&#8221;];&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>return<\/strong>&nbsp;Content(status);&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<\/li>\n\n\n\n<li>}&nbsp;&nbsp;<\/li>\n<\/ol>\n\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/static.javatpoint.com\/ado\/images\/ado-net-mvc-example1.png\" alt=\"ADO Net Mvc Example 1\"\/><\/figure>\n\n\n\n<p>After submitting, it stores and fetches data from the SQL Server database and produce the following result to the browser.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/static.javatpoint.com\/ado\/images\/ado-net-mvc-example2.png\" alt=\"ADO Net Mvc Example 2\"\/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MVC (Model View Controller) is a web&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4579,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[189,140],"tags":[578,191,577],"class_list":["post-4578","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-asp-net","category-programming","tag-ado-net","tag-asp-net","tag-mvc"],"_links":{"self":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/comments?post=4578"}],"version-history":[{"count":1,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4578\/revisions"}],"predecessor-version":[{"id":4580,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/posts\/4578\/revisions\/4580"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/media\/4579"}],"wp:attachment":[{"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/media?parent=4578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/categories?post=4578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/isophal.com\/news\/wp-json\/wp\/v2\/tags?post=4578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}