Refer the below sample code for your reference and implement in your code as per your code logic.
SQL
CREATE TABLE [Event] (EventId INT,EventDescription VARCHAR(100))
CREATE TABLE [Transaction](EventId INT,EmployeeId INT, EmployeeName Varchar(20))
INSERT INTO [Event](EventId,EventDescription)
SELECT 1,'Event Description 1'
UNION ALL
SELECT 2,'Event Description 2'
UNION ALL
SELECT 3,'Event Description 3'
UNION ALL
SELECT 4,'Event Description 4'
UNION ALL
SELECT 5,'Event Description 5'
UNION ALL
SELECT 6,'Event Description 6'
UNION ALL
SELECT 7,'Event Description 7'
INSERT INTO [Transaction](EventId ,EmployeeId, EmployeeName)
SELECT 1,1,'Rajesh'
UNION ALL
SELECT 2,1,'Rajesh'
UNION ALL
SELECT 4,1,'Rajesh'
UNION ALL
SELECT 6,1,'Rajesh'
UNION ALL
SELECT 3,2,'Viraj'
UNION ALL
SELECT 5,2,'Viraj'
UNION ALL
SELECT 7,2,'Viraj'
UNION ALL
SELECT 2,3,'Samit'
UNION ALL
SELECT 5,3,'Samit'
UNION ALL
SELECT 6,3,'Samit'
UNION ALL
SELECT 7,3,'Samit'
-- EXEC GETTransactionDetails
CREATE PROCEDURE GETTransactionDetails
AS
BEGIN
SELECT E.EventId
,E.EventDescription
,T.EmployeeId
,T.EmployeeName
FROM [Transaction] T INNER JOIN [Event] E
ON T.EventId = E.EventId
END
GO
HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
table
{
border: 1px solid #ccc;
}
table th
{
background-color: #F7F7F7;
color: #333;
font-weight: bold;
}
table th, table td
{
padding: 5px;
border-color: #ccc;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvTransactionDetails" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Event Id" DataField="EventId" />
<asp:BoundField HeaderText="Event Description" DataField="EventDescription" />
<asp:BoundField HeaderText="Employee Id" DataField="EmployeeId" />
<asp:BoundField HeaderText="Employee Name" DataField="EmployeeName" />
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
GetTransactionDetails();
}
}
private void GetTransactionDetails()
{
string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GETTransactionDetails";
cmd.Connection = con;
con.Open();
gvTransactionDetails.EmptyDataText = "No Records Found";
gvTransactionDetails.DataSource = cmd.ExecuteReader();
gvTransactionDetails.DataBind();
con.Close();
con.Dispose();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
GetTransactionDetails()
End If
End Sub
Private Sub GetTransactionDetails()
Dim strConnString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim con As SqlConnection = New SqlConnection(strConnString)
Dim cmd As SqlCommand = New SqlCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "GETTransactionDetails"
cmd.Connection = con
con.Open()
gvTransactionDetails.EmptyDataText = "No Records Found"
gvTransactionDetails.DataSource = cmd.ExecuteReader()
gvTransactionDetails.DataBind()
con.Close()
con.Dispose()
End Sub
Screenshot
