Hi Mehram,
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<asp:Label ID="lblName" runat="server" />
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data.SqlClient
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string query = "SELECT TOP 1 '<b>' + FirstName + '</b> ' + LastName 'Name' FROM Employees";
using (SqlConnection con = new SqlConnection(conString))
{
SqlCommand cmd = new SqlCommand(query);
cmd.Connection = con;
con.Open();
string name = Convert.ToString(cmd.ExecuteScalar());
con.Close();
lblName.Text = name;
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim query As String = "SELECT TOP 1 '<b>' + FirstName + '</b> ' + LastName 'Name' FROM Employees"
Using con As SqlConnection = New SqlConnection(conString)
Dim cmd As SqlCommand = New SqlCommand(query)
cmd.Connection = con
con.Open()
Dim name As String = Convert.ToString(cmd.ExecuteScalar())
con.Close()
lblName.Text = name
End Using
End If
End Sub
Screenshot