ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Display validation message based on Table and Column availability in database using AngularJS in ASP.Net MVC<p>Hi&nbsp;<a class="username" rel="mahesh213">mahesh213,</a></p> <p>Check this example. Now please take its reference and correct your code.</p> <p>Note : Based on your condition change&nbsp;the code accordingly.</p> <p><strong><span style="text-decoration: underline;">Controller</span></strong></p> <pre class="brush: csharp">public class HomeController : Controller { // GET: /Home/ public ActionResult Index() { return View(); } public JsonResult ValidateTable(string tableName) { string exist; SqlConnection con = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; con.ConnectionString = connectionstring; SqlCommand cmd = new SqlCommand(&#34;SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @Name&#34;, con); cmd.Parameters.AddWithValue(&#34;@Name&#34;, tableName); con.Open(); exist = Convert.ToString(cmd.ExecuteScalar()); return Json(exist, JsonRequestBehavior.AllowGet); } public JsonResult ValidateColumnName(string tableName, string columnName) { string exist; SqlConnection con = new SqlConnection(); string connectionstring = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; con.ConnectionString = connectionstring; SqlCommand cmd = new SqlCommand(&#34;SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @Table AND COLUMN_NAME = @Column&#34;, con); cmd.Parameters.AddWithValue(&#34;@Table&#34;, tableName); cmd.Parameters.AddWithValue(&#34;@Column&#34;, columnName); con.Open(); exist = Convert.ToString(cmd.ExecuteScalar()); return Json(exist, JsonRequestBehavior.AllowGet); } }</pre> <p><strong><span style="text-decoration: underline;">View</span></strong></p> <pre class="brush: html">&lt;html&gt; &lt;head&gt; &lt;title&gt;Index&lt;/title&gt; &lt;link rel=&#34;stylesheet&#34; href=&#34;https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; var app = angular.module(&#34;MyApp&#34;, []); app.controller(&#34;MyController&#34;, function ($scope, $http) { $scope.Details = [{ CName: &#34;Fromdate&#34;, CType: &#39;audi&#39;, FromTable: &#39;&#39;, DisplayCName: &#39;&#39;, ValueCName: &#39;&#39;, Date: &#39;&#39; }, { CName: &#34;Todate&#34;, CType: &#39;audi&#39;, FromTable: &#39;&#39;, DisplayCName: &#39;&#39;, ValueCName: &#39;&#39;, Date: &#39;&#39;}]; for (var i = 0; i &lt; $scope.Details.length; i++) { $scope.Details[i][&#34;isDisabledFromTable&#34;] = true; $scope.Details[i][&#34;isDisabledDisplayCName&#34;] = true; $scope.Details[i][&#34;isDisabledValueCName&#34;] = true; $scope.Details[i][&#34;isDisabledDate&#34;] = true; } $scope.TypeChange = function (cType, cName, index) { $scope.Details[index].FromTable = &#34;&#34;; $scope.Details[index].DisplayCName = &#34;&#34;; $scope.Details[index].ValueCName = &#34;&#34;; for (var i = 0; i &lt; $scope.Details.length; i++) { if ($scope.Details[i].CName == cName) { if (cType == &#34;Dropdown&#34;) { $scope.Details[i][&#34;isDisabledDate&#34;] = true; $scope.Details[i][&#34;isDisabledFromTable&#34;] = false; $scope.Details[i][&#34;isDisabledDisplayCName&#34;] = false; $scope.Details[i][&#34;isDisabledValueCName&#34;] = false; } else if (cType == &#34;DatePicker&#34;) { $scope.Details[i][&#34;isDisabledFromTable&#34;] = true; $scope.Details[i][&#34;isDisabledDisplayCName&#34;] = true; $scope.Details[i][&#34;isDisabledValueCName&#34;] = true; $scope.Details[i][&#34;isDisabledDate&#34;] = false; $scope.Details[i][&#34;TableMessage&#34;] = &#34;&#34;; $scope.Details[i][&#34;DisplayNameMessage&#34;] = &#34;&#34;; $scope.Details[i][&#34;ValueNameMessage&#34;] = &#34;&#34;; } else if (cType == &#34;Textbox&#34;) { $scope.Details[i][&#34;isDisabledFromTable&#34;] = true; $scope.Details[i][&#34;isDisabledDisplayCName&#34;] = true; $scope.Details[i][&#34;isDisabledValueCName&#34;] = true; $scope.Details[i][&#34;isDisabledDate&#34;] = true; $scope.Details[i][&#34;TableMessage&#34;] = &#34;&#34;; $scope.Details[i][&#34;DisplayNameMessage&#34;] = &#34;&#34;; $scope.Details[i][&#34;ValueNameMessage&#34;] = &#34;&#34;; } else { $scope.Details[i][&#34;isDisabledFromTable&#34;] = true; $scope.Details[i][&#34;isDisabledDisplayCName&#34;] = true; $scope.Details[i][&#34;isDisabledValueCName&#34;] = true; $scope.Details[i][&#34;isDisabledDate&#34;] = true; $scope.Details[i][&#34;TableMessage&#34;] = &#34;&#34;; $scope.Details[i][&#34;DisplayNameMessage&#34;] = &#34;&#34;; $scope.Details[i][&#34;ValueNameMessage&#34;] = &#34;&#34;; } } } } $scope.ValidateTable = function (table, index) { if (table != &#39;&#39;) { $http({ method: &#34;post&#34;, url: &#34;/Home/ValidateTable&#34;, params: { tableName: table } }).then(function (response) { for (var i = 0; i &lt; $scope.Details.length; i++) { if (i == index) { if (response.data == &#39;&#39;) { $scope.Details[i][&#34;TableColor&#34;] = &#34;Red&#34;; $scope.Details[i][&#34;TableMessage&#34;] = &#34;Table name not avaliable.&#34;; } else { $scope.Details[i][&#34;TableColor&#34;] = &#34;Green&#34;; $scope.Details[i][&#34;TableMessage&#34;] = &#34;Table name avaliable.&#34;; } } } }); } else { for (var i = 0; i &lt; $scope.Details.length; i++) { if (i == index) { $scope.Details[i][&#34;TableMessage&#34;] = &#34;&#34;; } } } } $scope.ValidateDisplayName = function (table, index, columnName) { if (columnName != &#39;&#39; &amp;&amp; table != &#39;&#39;) { $http({ method: &#34;post&#34;, url: &#34;/Home/ValidateColumnName&#34;, params: { tableName: table, columnName: columnName } }).then(function (response) { for (var i = 0; i &lt; $scope.Details.length; i++) { if (i == index) { if (response.data == &#39;&#39;) { $scope.Details[i][&#34;DisplayNameColor&#34;] = &#34;Red&#34;; $scope.Details[i][&#34;DisplayNameMessage&#34;] = &#34;Column name not avaliable.&#34;; } else { $scope.Details[i][&#34;DisplayNameColor&#34;] = &#34;Green&#34;; $scope.Details[i][&#34;DisplayNameMessage&#34;] = &#34;Column name avaliable.&#34;; } } } }); } else { if (columnName == &#39;&#39;) { for (var i = 0; i &lt; $scope.Details.length; i++) { if (i == index) { $scope.Details[i][&#34;DisplayNameMessage&#34;] = &#34;&#34;; } } } } } $scope.ValidateValueName = function (table, index, columnName) { if (columnName != &#39;&#39; &amp;&amp; table != &#39;&#39;) { $http({ method: &#34;post&#34;, url: &#34;/Home/ValidateColumnName&#34;, params: { tableName: table, columnName: columnName } }).then(function (response) { for (var i = 0; i &lt; $scope.Details.length; i++) { if (i == index) { if (response.data == &#39;&#39;) { $scope.Details[i][&#34;ValueNameColor&#34;] = &#34;Red&#34;; $scope.Details[i][&#34;ValueNameMessage&#34;] = &#34;Column name not avaliable.&#34;; } else { $scope.Details[i][&#34;ValueNameColor&#34;] = &#34;Green&#34;; $scope.Details[i][&#34;ValueNameMessage&#34;] = &#34;Column name avaliable.&#34;; } } } }); } else { if (columnName == &#39;&#39;) { for (var i = 0; i &lt; $scope.Details.length; i++) { if (i == index) { $scope.Details[i][&#34;ValueNameMessage&#34;] = &#34;&#34;; } } } } } }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div ng-app=&#34;MyApp&#34; ng-controller=&#34;MyController&#34;&gt; &lt;table id=&#34;tblOrders&#34; class=&#34;table table-responsive&#34;&gt; &lt;tr&gt; &lt;th&gt;Cname&lt;/th&gt; &lt;th&gt;Ctype&lt;/th&gt; &lt;th&gt;From Table&lt;/th&gt; &lt;th&gt;DisplayCName&lt;/th&gt; &lt;th&gt;ValueCName&lt;/th&gt; &lt;th&gt;Date&lt;/th&gt; &lt;/tr&gt; &lt;tbody ng-repeat=&#34;detail in Details&#34;&gt; &lt;tr&gt; &lt;td&gt;{{detail.CName}}&lt;/td&gt; &lt;td&gt; &lt;select ng-model=&#34;detail.CType&#34; class=&#34;form-control&#34; ng-change=&#34;TypeChange(detail.CType,detail.CName,$index)&#34;&gt; &lt;option value=&#34;audi&#34; selected&gt;Select value&lt;/option&gt; &lt;option value=&#34;Dropdown&#34;&gt;Dropdown&lt;/option&gt; &lt;option value=&#34;Textbox&#34;&gt;Textbox&lt;/option&gt; &lt;option value=&#34;DatePicker&#34;&gt;DatePicker&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;td&gt; &lt;input type=&#34;text&#34; class=&#34;form-control&#34; ng-model=&#34;detail.FromTable&#34; ng-disabled=&#34;detail.isDisabledFromTable&#34; ng-keyup=&#34;ValidateTable(detail.FromTable,$index)&#34; /&gt; &lt;span ng-style=&#34;{color:detail.TableColor}&#34; ng-bind=&#34;detail.TableMessage&#34;&gt;&lt;/span&gt; &lt;/td&gt; &lt;td&gt; &lt;input type=&#34;text&#34; class=&#34;form-control&#34; ng-model=&#34;detail.DisplayCName&#34; ng-disabled=&#34;detail.isDisabledDisplayCName&#34; ng-keyup=&#34;ValidateDisplayName(detail.FromTable,$index,detail.DisplayCName)&#34; /&gt; &lt;span ng-style=&#34;{color:detail.DisplayNameColor}&#34; ng-bind=&#34;detail.DisplayNameMessage&#34;&gt; &lt;/span&gt; &lt;/td&gt; &lt;td&gt; &lt;input type=&#34;text&#34; class=&#34;form-control&#34; ng-model=&#34;detail.ValueCName&#34; ng-disabled=&#34;detail.isDisabledValueCName&#34; ng-keyup=&#34;ValidateValueName(detail.FromTable,$index,detail.ValueCName)&#34; /&gt; &lt;span ng-style=&#34;{color:detail.ValueNameColor}&#34; ng-bind=&#34;detail.ValueNameMessage&#34;&gt; &lt;/td&gt; &lt;td&gt; &lt;select ng-model=&#34;detail.Date&#34; class=&#34;form-control&#34; ng-disabled=&#34;detail.isDisabledDate&#34;&gt; &lt;option value=&#34;Today&#34;&gt;Today&lt;/option&gt; &lt;option value=&#34;Lastday&#34;&gt;Lastday&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://i.imgur.com/euZus3G.gif" alt="" width="472" height="141" /></span></strong></p>https://www.aspforums.net:443/Threads/119076/Display-validation-message-based-on-Table-and-Column-availability-in-database-using-AngularJS-in-ASPNet-MVC/https://www.aspforums.net:443/Threads/119076/Display-validation-message-based-on-Table-and-Column-availability-in-database-using-AngularJS-in-ASPNet-MVC/Tue, 14 May 2019 06:41:35 GMT