Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi I am Working on asp Grid by getting datas from one table and Updating details from other table

What I have tried:

HTML
<pre>
Alter procedure [dbo].[Sampe3](@years int,@months int)
as

;with t1 as (
SELECT DeptID, COUNT(EmpID) AS TotalHeadCount  FROM EmployeeDetails          
WHERE (datepart(yyyy,DOJ) between 2005 and @years) and Status =0
group by DeptID
),
t2 as (
SELECT  DeptID,COUNT(EmpID) AS NewJoinees FROM EmployeeDetails AS EmployeeDetails_7        
WHERE (DATEPART(yyyy, DOJ) = @years) AND (DATEPART(mm, DOJ)  = @months) and datepart(mm,DOJ)>= @months and Status = 0
group by DeptID
),
t3 as (
SELECT   DeptID,COUNT(EmpID) AS Resigned FROM  EmployeeDetails AS EmployeeDetails_7                           
WHERE (DATEPART(yyyy, deactivate) = @years) AND (DATEPART(mm, deactivate)  = @months) and datepart(mm,deactivate)>= @months and Status =1 group by DeptID
)
Select t1.DeptID, CASE WHEN TotalHeadCount IS NULL THEN '0' ELSE TotalHeadCount END AS TotalHeadCount,CASE WHEN NewJoinees IS NULL THEN '0' ELSE NewJoinees END AS NewJoinees,CASE WHEN Resigned IS NULL THEN '0' ELSE Resigned END AS Resigned, '' as ToBeHired, '' as OpenPositions, '' as Status
from t1 full outer join t2 on t1.DeptID = t2.DeptID
full outer join t3 on t1.DeptID = t3.DeptID
union
Select 'ZTotal' as total, '' as TotalHeadCount, '' as NewJoinees, '' as Resigned, '' as ToBeHired, '' as OpenPositions, '' as Status

(Update RecruitmentDetails set Tobehired=@Tobehired, OpenPosition=@OpenPosition, Status=@Status) As Update



<asp:GridView ID="grdvEmployeeLeaveUpdate" runat="server" DataKeyNames="" 
                         class="table table-bordered table-striped table-hover" DataSourceID="SqlDataSourceHeadCount"   
                        OnRowDataBound="grdvEmployeeLeaveUpdate_RowDataBound"  Width="100%"
                        OnRowDeleting="grdvEmployeeLeaveUpdate_RowDeleting"
                        OnRowEditing="grdvEmployeeLeaveUpdate_RowEditing"
                        OnRowUpdating="grdvEmployeeLeaveUpdate_RowUpdating"
                        OnRowCancelingEdit="grdvEmployeeLeaveUpdate_RowCancelingEdit"
                         OnPageIndexChanging="grdvEmployeeLeaveUpdate_PageIndexChanging">
                        
                        <Columns>
                            <asp:BoundField DataField="DeptID"  HeaderText="Cost Center" ReadOnly="true" ControlStyle-Width="50px"  />
                            <asp:BoundField DataField="TotalHeadCount" HeaderText="HeadCount" ReadOnly="true" ControlStyle-Width="50px"   />
                            <asp:BoundField DataField="NewJoinees" HeaderText="Additions" ReadOnly="true" ControlStyle-Width="50px"  />
                            <asp:BoundField DataField="Resigned" HeaderText="Separations" ReadOnly="true" ControlStyle-Width="50px"  />
                            <asp:BoundField DataField="ToBeHired" HeaderText="To Be Hired"  ControlStyle-Width="50px" />
                            <asp:BoundField DataField="OpenPositions" HeaderText="Open Position" ControlStyle-Width="50px" />
                            <asp:BoundField DataField="Status" HeaderText="Status"  ControlStyle-Width="50px" />
                            <asp:CommandField HeaderText="Update" ShowEditButton="True" ControlStyle-Width="50px" />
                            
                        </Columns>
                        <HeaderStyle></HeaderStyle>
                    </asp:GridView>


<asp:SqlDataSource ID="SqlDataSourceHeadCount" runat="server" ConnectionString="<%$ ConnectionStrings:TimeSheetConnectionString2 %>"
                                        SelectCommandType="StoredProcedure" SelectCommand="Sampe3">
                                        <SelectParameters>
                                            <asp:ControlParameter ControlID="ddlMonths" Name="months" Type="Int32" />
                                            <asp:ControlParameter ControlID="ddlyear" Name="years" Type="Int32" />
                                        </SelectParameters>
                                    </asp:SqlDataSource>
Posted
Comments
CHill60 28-Apr-17 11:09am    
Please state your question clearly in the body of the question (not the Title). Some sample data and an example of your expected results will help greatly.
Only include the code that is relevant to your problem. Use the Improve question link to update your question.
CHill60 28-Apr-17 11:19am    
One hint I can give you straight away ... Replace
CASE WHEN TotalHeadCount IS NULL THEN '0' ELSE TotalHeadCount END AS TotalHeadCount,
CASE WHEN NewJoinees IS NULL THEN '0' ELSE NewJoinees END AS NewJoinees,CASE WHEN Resigned IS NULL THEN '0' ELSE Resigned END AS Resigned, 
with the following
ISNULL(TotalHeadCount, 0) AS TotalHeadCount,ISNULL(NewJoinees, 0) AS NewJoinees,ISNULL(Resigned, 0) AS Resigned, 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900