Sunday, February 26, 2012

DataBinding: System.Data.DataRowView does not contain a property with the name Component_P

Hi,

Seems like a lot of people are having a similiar problem that I am having right now, but I am not able to find the solution to it. On the Page_load event, the gridview does display the data from database. When I click a button to insert the same data but different Waste_Profile_Num value, it gives me the databinding error. Component_Profile_ID is declared as an Identity and it is the primary key to the table. Anyway help?

Ok, the following are code that I have:

1 <asp:SqlDataSource ID="sqlDSMaterialComposition" runat="server" ConnectionString="<%$ ConnectionStrings:HAZConnectionString %>"2 SelectCommand="SELECT dbo.Component_Profile.Component_Profile_ID AS Component_Profile_ID, dbo.Component.Component, dbo.Component_Profile.Concentration, dbo.Component_Profile.Range, dbo.Component_Profile.Waste_Profile_Num, dbo.Component.Component_ID FROM dbo.Component INNER JOIN dbo.Component_Profile ON dbo.Component.Component_ID = dbo.Component_Profile.Component_ID WHERE (dbo.Component_Profile.Waste_Profile_Num = @.Waste_Profile_Num)">3 <SelectParameters>4 <asp:SessionParameter Name="Waste_Profile_Num" SessionField="Waste_Profile_Num" Type="Int32" />5 </SelectParameters>6 </asp:SqlDataSource>789 <asp:GridView ID="GridViewMaterialComposition"10 runat="server"11 DataKeyNames="Component_Profile_ID,Component_ID"12 AutoGenerateColumns="False" ShowFooter="true">13 <Columns>14 <asp:BoundField DataField="Component" HeaderText="Component" SortExpression="Component" FooterText="Total"/>15 <asp:TemplateField HeaderText="Concentration" FooterStyle-Font-Bold="true">16 <ItemTemplate>17 <%# SumConcentration(decimal.Parse(Eval("Concentration").ToString())).tostring("N2") %>18 </ItemTemplate>19 <FooterTemplate>20 <%# GetConcentration().tostring("N2") %>21 </FooterTemplate>22 </asp:TemplateField>23 <asp:BoundField DataField="Range" HeaderText="Range" SortExpression="Range" />24 <asp:BoundField DataField="Component_Profile_ID" HeaderText="Component_Profile_ID" ReadOnly="True" SortExpression="Component_Profile_ID" Visible="true" />25 <asp:BoundField DataField="Component_ID" HeaderText="Component_ID" ReadOnly="True" SortExpression="Component_ID" Visible="true"/>26 <asp:BoundField DataField="Waste_Profile_Num" HeaderText="Waste_Profile_Num" ReadOnly="true" SortExpression="Waste_Profile_Num" Visible="true" />27 <asp:CommandField ShowEditButton="true" />28 <asp:TemplateField Visible="false">29 <ItemTemplate>30 <asp:Label ID="lblComponentProfileID" runat="Server" Text='<% # Eval("Component_Profile_ID") %>'></asp:Label>31 <asp:Label ID="lblComponentID" runat="Server" Text='<% # Eval("Component_ID") %>'></asp:Label>32 </ItemTemplate>33 </asp:TemplateField>34 </Columns>35 </asp:GridView>
The following are the code-behind:
 
1 sqlSelect ="SELECT Range, Concentration, Component_ID FROM Component_Profile WHERE (Component_Profile.Waste_Profile_Num = " & previousWasteProfileNum &")"2 sqlDSMaterialComposition.SelectCommand = sqlSelect3Try4 Dim dvCompositionAs Data.DataView =CType(sqlDSMaterialComposition.Select(DataSourceSelectArguments.Empty), Data.DataView)5For Each drAs Data.DataRowIn dvComposition.Table.Rows6 insertSql ="INSERT INTO Component_Profile ([Range], [Concentration], [Component_ID], [Waste_Profile_Num]) "7 insertSql &="VALUES (" & dr("Range").ToString.Trim &", " & dr("Concentration").ToString.Trim &", " & dr("Component_ID").ToString.Trim &", " &CInt(Session("Waste_Profile_Num").ToString()) &")"8 sqlDSMaterialComposition.InsertCommand = insertSql9 sqlDSMaterialComposition.Insert()10Next11 Catch exAs Exception1213End Try

Hi guys,

that's ok. I have figured that out. I just need to databind the gridview after the for each statement