Reputation: 1905
I have two tables in my database named...Requests and Balance tracker which has no relation....but i want to select data from two tables and binf it two grid...
Requests
EmpID |EmpRqsts|EmpDescription|ApproverID
1 |asdfsb |sadbfsbdf |1
2 |asbfd |sjkfbsd |1
Balance Tracker
EmpId|BalanceAmnt|LastUpdated
| 1 |5000 |sdfbk
| 2 |3000 |sjbfsh
Employee Table
EmpId|EmpName
1 |Anil
2 |Raghu
Now Balance tracker has ForeignKey column of EmployeeTable... What I want is to select [EmpName ] from EmpTable [EmpRqsts] from [Requests] and [BalanceAmnt][LastUpdated] from [Balance Tracker] and bind it to grid
This is my stored procedure I am using to retrieve the data
create procedure SP_GetEmployeeRequests
(@ApproverName varchar (50))
as
begin
select
EmployeeDetails.Emp_Username,
RequestDetails.Request_Amount,
RequestDetails.Request_description,
BalanceTracker.Balance_Amount,
BalanceTracker.LastApproval,
BalanceTracker.LastUdated
from
EmployeeDetails, RequestDetails, BalanceTracker
where
EmployeeDetails.Emp_ID = RequestDetails.Emp_ID
and BalanceTracker.Emp_ID = RequestDetails.Emp_ID
and RequestDetails.Approved_ID = (select Approved_ID
from ApprovalDetails
where Approved_By = @ApproverName)
end
Everything is fine till here but this query is retrieving only the column names. But not the values of the tables..can any one help me whats wrong in my query..
Upvotes: 1
Views: 468
Reputation: 1905
I solved my answer thanks for evere one who tried to help me....i am posting my answer,so that it can be help full to any one in need...
CREATE procedure SP_GetEmployeeRequests
(
@ApproverName varchar (50)
)
AS
BEGIN
SELECT PTS_Employee.Emp_Username, PTS_Requests.Request_RequestedAmount, PTS_Requests.Request_Description, PTS_BalanceTracker.Balance_BalanceAmount, PTS_BalanceTracker.Balance_LastApproval, PTS_BalanceTracker.Balance_LastUpdated
FROM PTS_Employee JOIN PTS_Requests ON PTS_Employee.Emp_ID = PTS_Requests.Emp_ID
JOIN PTS_BalanceTracker ON PTS_BalanceTracker.Emp_ID = PTS_Requests.Emp_ID
JOIN PTS_Approval ON PTS_Approval.Approval_ApprovedID = PTS_Requests.Approval_ApprovedID
WHERE PTS_Approval.Approval_ApprovedBY = @ApproverName
END
GO
Upvotes: 1
Reputation: 4892
Try this:
SqlDataAdapter da = new SqlDataAdapter("select t1.EmpName,t2.EmpRqsts,t3.BalanceAmnt,t3.LastUpdated from EmpTable as t1,Requests as t2,Balance_tracker as t3 where t1.sno=t2.sno and t1.sno=t3.sno", conn);
DataTable dt1 = new DataTable();
da.Fill(dt1);
GridView1.DataSource = dt1;
GridView1.DataBind();
Upvotes: 0