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.Check if User in Account Table exists in another table using C# in ASP.Net<p>Hi micah,</p> <p>I have created a sample. You need to change as per your requirement.</p> <p><span style="text-decoration: underline;">SQL</span></p> <pre class="brush: sql">CREATE PROC UserExistance &nbsp;&nbsp; &nbsp;@UserName VARCHAR(50) AS BEGIN &nbsp;&nbsp; &nbsp;SET NOCOUNT ON; &nbsp;&nbsp; &nbsp;IF EXISTS(SELECT UserName FROM User3 WHERE Username = @Username) &nbsp;&nbsp; &nbsp;BEGIN &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;IF EXISTS(SELECT UserName FROM USERFollow WHERE UserName = @UserName OR FriendUserName = @UserName) &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BEGIN &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;SELECT &#39;Exist&#39; AS UserStatus -- User Exist in follower table. &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;END &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ELSE &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;BEGIN &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;SELECT &#39;NotExist&#39; AS UserStatus -- User Not Exist in follower table. &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;END &nbsp;&nbsp; &nbsp;END &nbsp;&nbsp; &nbsp;ELSE &nbsp;&nbsp; &nbsp;BEGIN &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;SELECT &#39;User not activated / invalid user&#39; AS UserStatus -- User not activated / invalid user in User Table. &nbsp;&nbsp; &nbsp;END&nbsp;&nbsp; &nbsp; END --EXEC UserExistance &#39;Mic22&#39; --EXEC UserExistance &#39;ClassLady&#39; --EXEC UserExistance &#39;dharmendra&#39;</pre> <p><span style="text-decoration: underline;">HTML</span></p> <pre class="brush: html">&lt;div&gt; &lt;asp:Label ID=&#34;lblFound&#34; Text=&#34;Found&#34; runat=&#34;server&#34; Visible=&#34;false&#34; /&gt; &lt;asp:Label ID=&#34;lblNotFound&#34; Text=&#34;NotFound&#34; runat=&#34;server&#34; Visible=&#34;false&#34; /&gt; &lt;asp:Label ID=&#34;lblInvalidUser&#34; Text=&#34;Invalid User&#34; runat=&#34;server&#34; Visible=&#34;false&#34; /&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;">Code</span></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString[&#34;UserName&#34;] != null) { if (!IsPostBack) { DataTable dt = GetData(Request.QueryString[&#34;UserName&#34;]); if (dt.Rows.Count &gt; 0) { string userStatus = dt.Rows[0][&#34;UserStatus&#34;].ToString().ToLower(); if (userStatus == &#34;exist&#34;) { lblFound.Visible = true; } else if (userStatus == &#34;notexist&#34;) { lblNotFound.Visible = true; } else { lblInvalidUser.Visible = true; } } } } } private DataTable GetData(string userName) { DataTable dt = new DataTable(); string constr = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; string query = &#34;UserExistance&#34;; using (SqlConnection con = new SqlConnection(constr)) { using (SqlCommand cmd = new SqlCommand(query, con)) { con.Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue(&#34;@UserName&#34;, userName); using (SqlDataAdapter sda = new SqlDataAdapter(cmd)) { sda.Fill(dt); } con.Close(); } } return dt; }</pre> <p><span style="text-decoration: underline;">Screenshot</span></p> <p><img src="https://i.imgur.com/DckqR0S.gif" alt="" /></p>https://www.aspforums.net:443/Threads/598527/Check-if-User-in-Account-Table-exists-in-another-table-using-C-in-ASPNet/https://www.aspforums.net:443/Threads/598527/Check-if-User-in-Account-Table-exists-in-another-table-using-C-in-ASPNet/Wed, 27 Apr 2016 06:12:18 GMTCheck if User in Account Table exists in another table using C# in ASP.Net<p>you didnt show how you displayed it on lable, you only showed procedure</p>https://www.aspforums.net:443/Threads/598527/Check-if-User-in-Account-Table-exists-in-another-table-using-C-in-ASPNet/https://www.aspforums.net:443/Threads/598527/Check-if-User-in-Account-Table-exists-in-another-table-using-C-in-ASPNet/Wed, 27 Apr 2016 06:30:39 GMTCheck if User in Account Table exists in another table using C# in ASP.Net<p>I have modified my previous reply. Refer the below link.</p> <p><a href="http://www.aspforums.net/Threads/598527/How-to-check-if-a-User-in-a-User-Account-Table-is-in-another-table-called-UserFollow/Replies/1#Replies">http://www.aspforums.net/Threads/598527/How-to-check-if-a-User-in-a-User-Account-Table-is-in-another-table-called-UserFollow/Replies/1#Replies</a></p> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/598527/Check-if-User-in-Account-Table-exists-in-another-table-using-C-in-ASPNet/https://www.aspforums.net:443/Threads/598527/Check-if-User-in-Account-Table-exists-in-another-table-using-C-in-ASPNet/Wed, 27 Apr 2016 07:11:58 GMT