Hi nauna,
Please refer below sample.
HTML
<div>
<asp:Label ID="lblId" runat="server" />
<br />
<asp:Label ID="lblName" runat="server"></asp:Label>
<br />
<asp:Label ID="lblCountry" runat="server"></asp:Label>
</div>
Namespaces
C#
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
Code
C#
DataAccess.cs
public class DataAccess
{
public int Id { get; set; }
public string Name { get; set; }
public string Country { get; set; }
public void Select(int CustomerId)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("getCustomerID", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@CustomerId", CustomerId);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
Id = Convert.ToInt32(sdr["CustomerId"]);
Name = sdr["Name"].ToString();
Country = sdr["Country"].ToString();
}
con.Close();
}
}
}
}
Default.cs
protected void Page_Load(object sender, EventArgs e)
{
DataAccess access = new DataAccess();
access.Select(1);
lblId.Text = "Id is : <b> " + access.Id + "</b>";
lblName.Text = "Name is : <b> " + access.Name + "</b>";
lblCountry.Text = "Country is : <b> " + access.Country + "</b>";
}
Screenshot