Hi dorsa,
You code is working at our end.
You need to verify does your View return any row or not based on your condition.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
SQL
CREATE VIEW [dbo].[vw_GetEmployees] AS
SELECT * FROM Employees
HTML
Name:<asp:TextBox ID="txtName" runat="server" />
Country<asp:TextBox ID="txtCountry" runat="server" />
<br />
<asp:Button Text="Search" OnClick="Search" runat="server" />
<br />
Id is: <asp:Label ID="lblCostumerId" runat="server" />
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
protected void Search(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("SELECT EmployeeId FROM vw_GetEmployees WHERE FirstName LIKE '%" + txtName.Text + "%' and Country = '" + txtCountry.Text + "'", con))
{
SqlDataReader dr;
con.Open();
dr = cmd.ExecuteReader();
if (dr.Read())
{
lblCostumerId.Text = dr["EmployeeId"].ToString();
}
con.Close();
}
}
}
VB.Net
Protected Sub Search(ByVal sender As Object, ByVal e As EventArgs)
Using con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("constr").ConnectionString)
Using cmd As SqlCommand = New SqlCommand("SELECT EmployeeId FROM vw_GetEmployees WHERE FirstName LIKE '%" & txtName.Text & "%' and Country = '" + txtCountry.Text & "'", con)
Dim dr As SqlDataReader
con.Open()
dr = cmd.ExecuteReader()
If dr.Read() Then
lblCostumerId.Text = dr("EmployeeId").ToString()
End If
con.Close()
End Using
End Using
End Sub
Screenshot
![](https://i.imgur.com/qHenAVM.gif)