Member 14125505 Ответов: 0

Ошибка:привязка данных: 'system.data.common.datarecordinternal' не содержит свойства с именем 'empname_vc'


I'm trying to bind submit to values to the dropdown list from the sql database. I get the Error:DataBinding: 'System.Data.Common.DataRecordInternal' does not contain a property with the name 'EmpName_vc'. I cannot figure out what exactly is the issue. I want to bind data to the drop down based on the sql query passed.



<pre lang="c++"><pre>
protected void BindSubmitTo()
    {
       try
        {
            SqlDataReader dr;
            using (SqlCommand cmd = new SqlCommand("select D.EmpId_Int, E.EmpName_vc from Dept_PM_HOD_List D Left Join Gen_Employee E on D.EmpId_Int = E.EmpId_Int where D.LCode_Int = @intDeptId and D.EmpId_Int<> @intEmpId and(E.EmpType_vc ='PM' or(E.EmpType_vc = 'HOD'))", Cnn))
            cmd.Parameters.AddWithValue("@intDeptId", LocId.Text);
            cmd.Parameters.AddWithValue("@intEmpId", EmpID.Text);
            cmd.CommandType = CommandType.Text;
            Cnn.Open();

            using (SqlDataReader dr = cmd.ExecuteReader())
            {

                if (dr.HasRows)
                {
                    Submit_dd.DataSource = dr;
                    Submit_dd.DataTextField = "EmpName_vc";
                    Submit_dd.DataValueField = "EmpId_Int";
                    Submit_dd.DataBind();
                    Submit_dd.Items.Insert(0, new ListItem("--Select--", "0"));
                }

                Cnn.Close();
            }
        }


<pre> 
<div class="form-group col-sm-1">
                  <asp:DropDownList ID="Submit_dd" placeholder="" Cssclass="form-control" runat="server"></asp:DropDownList>
                  <asp:Label ID="sublbl_error" Text="" ForeColor="Red" runat="server" ></asp:Label>
              </div>
                </div>

         <div>
             <asp:GridView ID="gridview_TS"

                 CssClass="table table-striped table-hover"

                 runat="server"

                 GridLines="None"

                 AutoGenerateColumns="False"

                 AllowPaging="True"

                 AllowSorting="True"

                 PageSize="20"

                 DataKeyNames="EmpId_int,ProjectCode_int" DataSourceID="SqlDataSource1">
                 <Columns>

                     <asp:BoundField DataField="Chk_Int" HeaderText="Chk_Int" SortExpression="Chk_Int" Visible="False" />
                     <asp:TemplateField HeaderText="">
                         <ItemTemplate>
                             <asp:CheckBox ID="cbSelect" CssClass="form-control" runat="server" />

                         </ItemTemplate>
                     </asp:TemplateField>
                     <asp:BoundField DataField="EmpId_Int" HeaderText="EmpId_Int" />
                     <asp:BoundField DataField="TSDate_dt" HeaderText="Date" SortExpression="TSDate_dt" />
                     <asp:BoundField DataField="ProjectCode_int" HeaderText="Project Code" SortExpression="ProjectCode_int" />
                     <asp:BoundField DataField="ProjectName_vc" HeaderText="Project Name" SortExpression="ProjectName_vc" />

                     <asp:BoundField DataField="CCode_Int" HeaderText="CCode_Int" Visible="False" />
                     <asp:BoundField DataField="CostCode_vc" HeaderText="Cost Code Group" SortExpression="CostCode_vc" />
                     <asp:BoundField DataField="CCode_vc" HeaderText="Cost Code Description" SortExpression="CCode_vc" />

                     <asp:BoundField DataField="TSRhours_nu" HeaderText="Reg. Hours" SortExpression="TSRhours_nu" />
                     <asp:BoundField DataField="TSOhours_nu" HeaderText="OT. Hours" SortExpression="TSOhours_nu" />
                     <asp:BoundField DataField="JobDescp_vc" HeaderText="Job Narration" SortExpression="JobDescp_vc" />
                     <asp:BoundField DataField="EmpName_vc" HeaderText="Submit To" SortExpression="True" />
                     <asp:BoundField DataField="SubmitTo_Int" HeaderText="SubmitTo_Int" Visible="False" />

                 </Columns>
             </asp:GridView>
             <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TSMSConnectionString %>" 

                 SelectCommand="SELECT S.EmpId_Int, T.Chk_Int, T.TSDate_dt, T.ProjectCode_Int, P.ProjectName_vc, 
                 T.CCode_Int, C.CostCode_vc, C.CCode_vc, T.TSRhours_nu, T.TSOhours_nu, T.JobDescp_vc, E.EmpName_vc,
                  T.SubmitTo_Int FROM TSHistory T LEFT JOIN Sec_Users S ON T.EmpId_Int= S.EmpId_Int 
                 LEFT JOIN Gen_ProjectList P ON T.ProjectCode_Int = P.ProjectCode_Int 
                 LEFT JOIN Gen_CCList C ON T.CCode_Int= C.CCode_Int LEFT JOIN Gen_Employee E 
                 ON T.EmpId_Int = E.EmpId_Int WHERE (S.UserId_vc = @userId) AND (T.SubmitTo_Int = 0) ORDER BY T.TSDate_dt DESC ">

                 <SelectParameters>
                     <asp:SessionParameter DefaultValue ="" Name="userId" SessionField="user" Type="string" />
                 </SelectParameters>

             </asp:SqlDataSource>
         </div>

         <div class="btn btm-default btn-block" style="width:100%">
             <asp:Button ID="create_TS" runat="server" Text="Create" class="btn btn-success mr-5" OnClick="btnCreate_click" />
             <asp:Button ID="delete_TS" runat="server" Text="Delete" class="btn btn-danger mr-5" />
             <asp:Button ID="update_TS" runat="server" Text="Update" class="btn btn-info mr-5" />
             <asp:Button ID="clear_TS" runat="server" Text="Clear" CssClass="btn btn-outline-light mr-5" />
        </div>


Что я уже пробовал:

Я не могу привязать submit к выпадающему списку на основе переданного запроса.

Gerry Schmitz

- Посмотрите в считыватель данных и посмотрите, что извлекается, вместо того чтобы гадать.

Member 14125505

Если вы не можете помочь, то можете и не комментировать? Во всяком случае, это решено.

0 Ответов