---
title: "Show whether the record is find by Name or EmpID"  
description: "Show whether the record is find by Name or EmpID"  
author: "Anonymous User"  
published: 2013-06-19  
updated: 2013-06-19  
canonical: https://www.mindstick.com/forum/1217/show-whether-the-record-is-find-by-name-or-empid  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 2 minutes  

---

# Show whether the record is find by Name or EmpID

Hi Everyone,\
\
My line of code as following.\
\
using ([SqlConnection](https://www.mindstick.com/forum/1209/sqlconnection-sqlcommand-sqldatareader-idisposable) myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))\
{\
myDatabaseConnection.Open();\
using ([SqlCommand](https://www.mindstick.com/forum/91/difference-between-sqlcommand-and-sqlcommandbuilder) mySqlCommand = new SqlCommand("[Select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) EmpID, Name from [Employee](https://www.mindstick.com/articles/85431/remote-employee-training-tips-tricks) WHERE EmpID = @EmpID OR Name = @Name ", myDatabaseConnection))\
{\
mySqlCommand.Parameters.AddWithValue("@EmpID", textBox1.text);\
mySqlCommand.Parameters.AddWithValue("@Name", textBox1.text);\
[DataSet](https://www.mindstick.com/articles/19/dataset) ds = new DataSet();\
[SqlDataAdapter](https://www.mindstick.com/interview/33991/what-is-sqldataadapter) adapter = new SqlDataAdapter(mySqlCommand);\
adapter.Fill(ds);\
dataGridView1.DataSource = ds.Tables[0]; \
}\
}\
\
[Sample database](https://www.mindstick.com/forum/184/sample-database-in-sqlserver2005-2008)\
\
EmpID Name\
4001 Johnny Bravo\
4002 Bruce Smith\
4003 Vince Walker\
\
When I type 4001 on the textBox1 this is the [result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency)\
\
EmpID Name\
4001 Johnny Bravo\
\
And when I type Bruce Smith on the textBox1 this is the result\
\
EmpID Name\
4002 Bruce Smith\
\
What I need is to show whether the record is find by EmpID or Name. For example I type 4003 the [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) or label, etc will be like "The record is found by EmpID" . \
\
And when I type Vince Walker it will be like "The record is found by Name" .\
\
Any help would be amazing thank you!\

## Replies

### Reply by Sumit Kesarwani

Hi Expert,\
First off, you have a SQL injection vulnerability that you need to fix. This article should get you stared on parameterized queries.\
Secondly, you could slip a case statement into your query to indicate which value matched. Example:\
**SELECT CASE WHEN EmpID = @EmpId** **THEN 1** **ELSE 0** **END AS MatchedEmpId****FROM Whatever**


---

Original Source: https://www.mindstick.com/forum/1217/show-whether-the-record-is-find-by-name-or-empid

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
