Hi SUJAYS,
Refer below sample.
HTML
<div>
Id :<asp:TextBox runat="server" ID="txtId" />
<br />
<asp:Button Text="Submit" runat="server" OnClick="Insert" />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="CustomerId" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
</div>
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
Code
C#
BEL.cs
public class BEL
{
private int _Id;
public int id
{
get
{
return _Id;
}
set
{
_Id = value;
}
}
}
BLL.cs
public class BLL
{
public DataTable GetData(BEL enities)
{
DAL dal = new DAL();
return dal.Data(enities);
}
}
DAL.cs
public DataTable Data(BEL enities)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT Country FROM Customers WHERE CustomerId = @Id", con))
{
cmd.Parameters.AddWithValue("@Id", enities.id);
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
return dt;
}
}
}
}
CS.aspx.cs
protected void Submit(object sender, EventArgs e)
{
int id = Convert.ToInt32(txtId.Text.Substring(2, 1));
BEL entity = new BEL();
entity.id = Convert.ToInt32(id);
BLL bll = new BLL();
DataTable dt = bll.GetData(entity);
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
}
VB.Net
BELVB.vb
Private _Id As Integer
Public Property id As Integer
Get
Return _Id
End Get
Set(ByVal value As Integer)
_Id = value
End Set
End Property
BLLVB.vb
Public Function GetData(ByVal enities As BELVB) As DataTable
Dim dal As DALVB = New DALVB()
Return dal.Data(enities)
End Function
DALVB.vb
Public Function Data(ByVal enities As BELVB) As DataTable
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("SELECT CustomerId, Country, Name FROM Customers WHERE CustomerId = @Id", con)
cmd.Parameters.AddWithValue("@Id", enities.id)
Using da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
Return dt
End Using
End Using
End Using
End Function
VB.aspx.vb
Protected Sub Submit(ByVal sender As Object, ByVal e As EventArgs)
Dim id As Integer = Convert.ToInt32(txtId.Text.Substring(2, 1))
Dim entity As BELVB = New BELVB()
entity.id = Convert.ToInt32(id)
Dim bll As BLLVB = New BLLVB()
Dim dt As DataTable = bll.GetData(entity)
Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
End Sub
Screenshot