how to display int value from data base on label in asp.net c#

In this article, we learn about the how to fetch integer value the database value in label, Normally we need to this for account page means after the login, suppose we need to show the Contact number  in label.


Database:-                                         



Source Code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="labelvalue.aspx.cs" Inherits="labelvalue" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
   
    </div>
    </form>
</body>
</html>


Code behind(C#);-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class labelvalue : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {



        SqlConnection con = new SqlConnection("Data Source=NEERAJ-PC;Initial Catalog=CodeSolution;Persist Security Info=True;User ID=sa; password=12345678");
        con.Open();
        SqlCommand cmd = new SqlCommand("Select * from record where name ='Neeraj Srivastava'", con);
         
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            Label1.Text = dr["Contact_no"].ToString();

        }
        con.Close();

    }


}

Out-Put:-

how to display int value from data base on label in asp.net c# how to display int value from data base  on label in asp.net c# Reviewed by NEERAJ SRIVASTAVA on 8:13:00 PM Rating: 5

No comments:

Powered by Blogger.