while have adding another field, i have getting mention error.
my table values:-
3010 |
7221 |
Dharma Pratim |
IT |
2020-2021 |
11 |
18-12-2020 11:42:16 |
Lead |
Deviation |
1 |
sdfds |
N |
3011 |
7221 |
Dharma Pratim |
IT |
2020-2021 |
11 |
18-12-2020 11:42:16 |
Lead |
Near miss |
1 |
sadasd |
N |
3013 |
7221 |
Dharma Pratim |
IT |
2020-2021 |
11 |
18-12-2020 11:42:16 |
Lead |
Training |
1 |
sadasd |
N |
3014 |
7221 |
Dharma Pratim |
IT |
2020-2021 |
11 |
18-12-2020 11:42:16 |
Lead |
TBT_Pep_Talk |
1 |
asdas |
N |
3015 |
7221 |
Dharma Pratim |
IT |
2020-2021 |
11 |
18-12-2020 11:42:16 |
Lag |
Analaysis |
1 |
sadfasd |
N |
3016 |
7221 |
Dharma Pratim |
IT |
2020-2021 |
11 |
18-12-2020 11:42:16 |
Lag |
First Aid |
1 |
asdaSD |
N |
3017 |
7221 |
Dharma Pratim |
IT |
2020-2021 |
11 |
18-12-2020 11:42:16 |
Lag |
Fire |
1 |
AsdaS |
N |
3018 |
7221 |
Dharma Pratim |
IT |
2020-2021 |
11 |
18-12-2020 11:42:16 |
Lag |
Non-Reportable |
1 |
ASDAS |
N |
3019 |
7221 |
Dharma Pratim |
IT |
2020-2021 |
11 |
18-12-2020 11:42:16 |
Lag |
Fatal |
1 |
SADASDSA |
N |
3020 |
7221 |
Dharma Pratim |
IT |
2020-2021 |
11 |
18-12-2020 11:42:16 |
Lag |
Reportable |
1 |
safdsad |
N |
3012 |
7221 |
Dharma Pratim |
IT |
2020-2021 |
11 |
18-12-2020 11:42:16 |
Lead |
No of Visits |
1 |
sadfsa |
N |
NULL |
NULL |
NULL |
NULL |
NULL |
NULL |
NULL |
NULL |
NULL |
NULL |
NULL |
NULL |
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'TBT_Pep_Talk'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'TBT_Pep_Talk'. Source Error:
Line 92: <asp:TemplateField HeaderText="TBT Pep Talk">
Line 93: <ItemTemplate>
Line 94: <asp:LinkButton ID="TBT_Pep_Talk" Text='<%# Eval("TBT_Pep_Talk") %>' runat="server" OnClick="OnLeadLag" CommandName="TBT_Pep_Talk" />
Line 95: </ItemTemplate>
Line 96: </asp:TemplateField>
|
Source File: c:\Users\Administrator\Desktop\18Dec2020\sfty_Lead_lag\dept_report1.aspx Line: 94 Stack Trace:
namespace sfty_Lead_lag
{
public partial class dept_report1 : System.Web.UI.Page
{
private void BindGrid(string Month, string year)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("ld_lg_count3", con))
{
if (!string.IsNullOrEmpty(Month) && !string.IsNullOrEmpty(year))
{
cmd.Parameters.AddWithValue("@Month", Month);
cmd.Parameters.AddWithValue("@year", year);
}
cmd.CommandType = CommandType.StoredProcedure;
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.Visible = true;
this.GridView1.DataSource = dt;
this.GridView1.DataBind();
//decimal total = Convert.ToDecimal(dt.Rows[i][2].ToString());
decimal deviation, near_miss, first_Aid, fire, non_Reportable, reportable, fatal, TBT_Pep_Talk, Training;
deviation = dt.AsEnumerable().Sum(row => Convert.ToDecimal(row.Field<int?>("Deviation")));
near_miss = dt.AsEnumerable().Sum(row => Convert.ToDecimal(row.Field<int?>("Near miss")));
first_Aid = dt.AsEnumerable().Sum(row => Convert.ToDecimal(row.Field<int?>("First Aid")));
fire = dt.AsEnumerable().Sum(row => Convert.ToDecimal(row.Field<int?>("Fire")));
non_Reportable = dt.AsEnumerable().Sum(row => Convert.ToDecimal(row.Field<int?>("Non-Reportable")));
reportable = dt.AsEnumerable().Sum(row => Convert.ToDecimal(row.Field<int?>("Reportable")));
fatal = dt.AsEnumerable().Sum(row => Convert.ToDecimal(row.Field<int?>("Fatal")));
TBT_Pep_Talk = dt.AsEnumerable().Sum(row => Convert.ToDecimal(row.Field<int?>("TBT_Pep_Talk")));
Training = dt.AsEnumerable().Sum(row => Convert.ToDecimal(row.Field<int?>("Training")));
GridView1.FooterRow.Cells[0].Text = "Total";
GridView1.FooterRow.Cells[0].HorizontalAlign = HorizontalAlign.Right;
GridView1.FooterRow.Cells[1].Text = deviation.ToString("N0");
GridView1.FooterRow.Cells[2].Text = near_miss.ToString("N0");
GridView1.FooterRow.Cells[3].Text = first_Aid.ToString("N0");
GridView1.FooterRow.Cells[4].Text = fire.ToString("N0");
GridView1.FooterRow.Cells[5].Text = non_Reportable.ToString("N0");
GridView1.FooterRow.Cells[6].Text = reportable.ToString("N0");
GridView1.FooterRow.Cells[7].Text = fatal.ToString("N0");
GridView1.FooterRow.Cells[8].Text = TBT_Pep_Talk.ToString("N0");
GridView1.FooterRow.Cells[9].Text = Training.ToString("N0");
}
else
{
GridView1.Visible = false;
Label1.Visible = true;
Label1.Text = "The Records for Month " + ddl_Month.SelectedValue + " is not Available.";
}
}
}
}
}
}
}
CREATE PROCEDURE [dbo].[ld_lg_count3]
@Month nvarchar(10) = NULL
,@Year nchar(10) = NULL
AS
BEGIN
SET NOCOUNT ON;
SELECT * FROM
(
SELECT COUNT(b.INDICATER_TYPE)as totalRow,a.DEPARTMENT,b.INDICATER_Desc
FROM emp_mast_lead_lag a
LEFT OUTER JOIN lead_lag1 b ON a.EMPNO = b.EMPNO
WHERE (b.Month = @Month OR b.Month IS NULL)
AND (b.Year = @Year OR b.year IS NULL)
GROUP BY a.DEPARTMENT,b.INDICATER_Desc
) t
PIVOT (SUM(totalRow) FOR INDICATER_Desc IN ([Deviation],[Near miss],[First Aid],[Fire],[Non-Reportable],[Reportable],[Fatal]))P
END