Select query to format (bold) string in SQL Server

Mehram
 
on Jul 23, 2021 10:54 PM
Sample_490001.zip
691 Views

Sir, 

How could I send bold and unbold value from MS SQL Query string.

a will be bold while b will be unbold.

Please help 

Select a + b from abc 

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Jul 24, 2021 05:33 AM

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