rohit.net100 0 Newbie Poster

Hi ,
I am saving my grid data into my database. But problem is only my bound column data is saving, not template columns data, for template columns, it stores 'zeros'. I tried many method for converting string into integer(convert.int32, integer.parse, cint, integer. tryparse, ctype), but all methods gives me error that: input string was not in correct format.
Now i used VAL, there was no error, but it is storing 'zeros'. I check all my code and database for datatype, but can't figure out anything. Please help. Below is my code.
VB Code:

Public Sub AddGrid()
        For Each item As GridDataItem In GD_Prod.Items

            'getting the bound fields values 
            Dim str0 As String = item("port_recipe_num").Text
            Dim str1 As String = item("DESC_ALT").Text
            Dim str2 As String = item("port_no_servings").Text
            Dim str5 As String = item("STD_NUM_OF_SERVING").Text
            Dim str13 As String = item("POSStudents").Text
            Dim str14 As String = item("POSAdultsALC").Text


            ''''''getting the template fields value   
            Dim tx3 As TextBox = DirectCast(item.FindControl("TxtSTUPort"), TextBox)
            Dim tx4 As TextBox = DirectCast(item.FindControl("TxtAAPort"), TextBox)
            Dim tx6 As TextBox = DirectCast(item.FindControl("TxtFPort"), TextBox)
            Dim tx7 As TextBox = DirectCast(item.FindControl("TxtQoFUsed"), TextBox)
            Dim tx8 As TextBox = DirectCast(item.FindControl("TxtPPort"), TextBox)
            Dim tx9 As TextBox = DirectCast(item.FindControl("TxtBFPort"), TextBox)
            Dim tx10 As TextBox = DirectCast(item.FindControl("TxtLOPort"), TextBox)
            Dim tx11 As DropDownList = DirectCast(item.FindControl("ddlLOCode"), DropDownList)
            Dim tx12 As TextBox = DirectCast(item.FindControl("TxtTSPort"), TextBox)

            '''''inserting the template values 

            Dim str3 As String = (tx3.Text).Trim
            Dim str4 As String = (tx4.Text).Trim
            Dim str6 As String = (tx6.Text)
            Dim str7 As String = (tx7.Text)
            Dim str8 As String = (tx8.Text).Trim
            Dim str9 As String = (tx9.Text).Trim
            Dim str10 As String = (tx10.Text).Trim
            Dim str11 As String = tx11.SelectedItem.Value
            Dim str12 As String = (tx12.Text).Trim
            

            Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("FConnectionString").ConnectionString)
            Dim cmd As New SqlCommand("P_FN_PR_InsertGridData", con)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.Add("@Pkey", System.Data.SqlDbType.Char)
            cmd.Parameters("@Pkey").Value = lblPKey.Text.Trim
            cmd.Parameters.Add("@PL_Recipe_Number", System.Data.SqlDbType.Char)
            cmd.Parameters("@PL_Recipe_Number").Value = str0
            cmd.Parameters.Add("@PL_Recipe_Name", System.Data.SqlDbType.Char)
            cmd.Parameters("@PL_Recipe_Name").Value = str1
            cmd.Parameters.Add("@PL_Portion_Size", System.Data.SqlDbType.Char)
            cmd.Parameters("@PL_Portion_Size").Value = str2

            cmd.Parameters.Add("@PL_Student_Portions_Planned", System.Data.SqlDbType.Int)
            cmd.Parameters("@PL_Student_Portions_Planned").Value = Val(str3)

            cmd.Parameters.Add("@PL_Adults_ALC__Portions_Planned", System.Data.SqlDbType.Int)
            cmd.Parameters("@PL_Adults_ALC__Portions_Planned").Value = Val(str4)

            cmd.Parameters.Add("@PL_Total__Portions_Planned", System.Data.SqlDbType.Int)
            cmd.Parameters("@PL_Total__Portions_Planned").Value = Val(str5)

            cmd.Parameters.Add("@PL_Factor_Portions", System.Data.SqlDbType.Char)
            cmd.Parameters("@PL_Factor_Portions").Value = Val(str6)

            cmd.Parameters.Add("@DOC_Quantity_Of_Food_Used", System.Data.SqlDbType.Char)
            cmd.Parameters("@DOC_Quantity_Of_Food_Used").Value = Val(str7)

            cmd.Parameters.Add("@DOC_Portions_Prepared ", System.Data.SqlDbType.Int)
            cmd.Parameters("@DOC_Portions_Prepared ").Value = Val(str8)

            cmd.Parameters.Add("@DOC_Portions_Brought_Forward ", System.Data.SqlDbType.Int)
            cmd.Parameters("@DOC_Portions_Brought_Forward ").Value = Val(str9)

            cmd.Parameters.Add("@DOC_Portions_Leftover", System.Data.SqlDbType.Int)
            cmd.Parameters("@DOC_Portions_Leftover").Value = Val(str10)

            cmd.Parameters.Add("@DOC_Leftover_Code", System.Data.SqlDbType.Char)
            cmd.Parameters("@DOC_Leftover_Code").Value = Val(str11)

            cmd.Parameters.Add("@DOC_Total_Portions_Served", System.Data.SqlDbType.Int)
            cmd.Parameters("@DOC_Total_Portions_Served").Value = Val(str12)

            cmd.Parameters.Add("@DOC_Portions_Served_Students", System.Data.SqlDbType.Int)
            cmd.Parameters("@DOC_Portions_Served_Students").Value = Val(str13)

            cmd.Parameters.Add("@DOC_Portions_Served_Adults_ALC", System.Data.SqlDbType.Int)
            cmd.Parameters("@DOC_Portions_Served_Adults_ALC").Value = Val(str14)
            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
    Next
    End Sub

ASPX Code:

<telerik:RadGrid ID="GD_Prod" runat="server" AllowPaging="True" ShowHeader="False"
                    AutoGenerateColumns="False" GridLines="None" Height="173px" Skin="Outlook" Width="1107px">
                    <ValidationSettings EnableModelValidation="False" EnableValidation="False" />
                    <ClientSettings AllowColumnsReorder="True">
                        <Selecting AllowRowSelect="True" />
                        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                    </ClientSettings>
                    <MasterTableView>
                        <RowIndicatorColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </ExpandCollapseColumn>
                        <CommandItemSettings ExportToPdfText="Export to Pdf" ShowExportToPdfButton="True">
                        </CommandItemSettings>
                        <Columns>
                            <telerik:GridBoundColumn DataField="port_recipe_num" HeaderText="Recipe #" SortExpression="port_recipe_num"
                                UniqueName="port_recipe_num" DataType="System.Char">
                                <HeaderStyle Width="17px" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="DESC_ALT" HeaderText="Description" SortExpression="DESC_ALT"
                                UniqueName="DESC_ALT" DataType="System.Char">
                                <HeaderStyle Width="36px" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="port_no_servings" HeaderText="Portion Size" SortExpression="port_no_servings"
                                UniqueName="port_no_servings" DataType="System.Char">
                                <HeaderStyle Width="16px" />
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn UniqueName="PL_STUDENT_Portions_Planned" 
                                DataType="System.Int32" ForceExtractValue="Always" >
                                <ItemTemplate>
                                    <asp:TextBox ID="TxtSTUPort"  runat="server"
                                        
                                        Height="16px" Width="30px"></asp:TextBox>
                                </ItemTemplate>
                                <HeaderStyle Width="19px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="PL_Adults_ALC__Portions_Planned">
                                <ItemTemplate>
                                    <asp:TextBox ID="TxtAAPort"  runat="server"
                                        Height="16px" Width="30px"></asp:TextBox>
                                </ItemTemplate>
                                <HeaderStyle Width="19px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="STD_NUM_OF_SERVING" DataType="System.Int32" HeaderText="STD_NUM_OF_SERVING"
                                SortExpression="STD_NUM_OF_SERVING" UniqueName="STD_NUM_OF_SERVING">
                                <HeaderStyle Width="14px" />
                            </telerik:GridBoundColumn>
                            <telerik:GridTemplateColumn UniqueName="PL_Factor_Portions">
                                <ItemTemplate>
                                    <asp:TextBox ID="TxtFPort" runat="server" Height="16px"
                                        Width="30px"></asp:TextBox>
                                </ItemTemplate>
                                <HeaderStyle Width="18px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="DOC_Quantity_Of_Food_Used" >
                                <ItemTemplate>
                                    <asp:TextBox ID="TxtQoFUsed" runat="server"
                                        Height="16px" Width="30px"></asp:TextBox>
                                </ItemTemplate>
                                <HeaderStyle Width="20px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="DOC_Portions_Prepared" >
                                <ItemTemplate>
                                    <asp:TextBox ID="TxtPPort"  runat="server" Height="16px"
                                        Width="30px"></asp:TextBox>
                                </ItemTemplate>
                                <HeaderStyle Width="16px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="DOC_Portions_Brought_Forward" >
                                <ItemTemplate>
                                    <asp:TextBox ID="TxtBFPort"  runat="server"
                                        Height="16px" Width="30px"></asp:TextBox>
                                </ItemTemplate>
                                <HeaderStyle Width="16px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="DOC_Portions_LeftOver" >
                                <ItemTemplate>
                                    <asp:TextBox ID="TxtLOPort"  runat="server" Height="16px"
                                        Width="30px"></asp:TextBox>
                                </ItemTemplate>
                                <HeaderStyle Width="16px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="DOC_LeftOver_Code" >
                                <ItemTemplate>
                                    <asp:DropDownList ID="ddlLOCode"  runat="server" Font-Size="10px"
                                        Height="16px" Width="46px" AppendDataBoundItems="True">
                                        <asp:ListItem></asp:ListItem>
                                        <asp:ListItem>CF</asp:ListItem>
                                        <asp:ListItem>DIS</asp:ListItem>
                                        <asp:ListItem>ALC</asp:ListItem>
                                        <asp:ListItem>RTB</asp:ListItem>
                                        <asp:ListItem>RTF</asp:ListItem>
                                    </asp:DropDownList>
                                </ItemTemplate>
                                <HeaderStyle Width="16px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn UniqueName="DOC_Total_Portions_Served" >
                                <ItemTemplate>
                                    <asp:TextBox ID="TxtTSPort"  runat="server"
                                        Height="16px" Width="30px"></asp:TextBox>
                                </ItemTemplate>
                                <HeaderStyle Width="16px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn UniqueName="POSStudents" DataType="System.Int32" DataField="POSStudents"
                                HeaderText="POSStudents" SortExpression="POSStudents">
                                <HeaderStyle Width="18px" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="POSAdultsALC" DataType="System.Int32" DataField="POSAdultsALC"
                                HeaderText="POSAdultsALC" SortExpression="POSAdultsALC">
                                <HeaderStyle Width="16px" />
                            </telerik:GridBoundColumn>
                        </Columns>
                        <PagerStyle AlwaysVisible="True" Mode="NumericPages" PageButtonCount="5" />
                    </MasterTableView>
                    <PagerStyle Mode="NumericPages" PageButtonCount="5" />
                </telerik:RadGrid>

StoredProcedure:

ALTER PROCEDURE [DBO].P_FN_PR_InsertGridData
      
      (
      @Pkey char(15),
      @PL_Recipe_Number char(4),
      @PL_Recipe_Name char(20),
      @PL_Portion_Size char(6),
      @PL_Student_Portions_Planned int,
      @PL_Adults_ALC__Portions_Planned int,
      @PL_Total__Portions_Planned int,
      @PL_Factor_Portions char(10),
      @DOC_Quantity_Of_Food_Used char(10),
      @DOC_Portions_Prepared int,
      @DOC_Portions_Brought_Forward int,
      @DOC_Portions_Leftover int,
      @DOC_Leftover_Code char(3),
      @DOC_Total_Portions_Served int,
      @DOC_Portions_Served_Students int,
      @DOC_Portions_Served_Adults_ALC int
      )
      
AS
begin
INSERT INTO FNProdRecDetails (Date_Loc_Type, PL_Recipe_Number, PL_Recipe_Name, PL_Portion_Size, PL_Student_Portions_Planned, PL_Adults_ALC__Portions_Planned, 
PL_Total__Portions_Planned, PL_Factor_Portions, DOC_Quantity_Of_Food_Used, DOC_Portions_Prepared, DOC_Portions_Brought_Forward, DOC_Portions_Leftover,
DOC_Leftover_Code, DOC_Total_Portions_Served, DOC_Portions_Served_Students, DOC_Portions_Served_Adults_ALC, System_Date)

VALUES (@Pkey , @PL_Recipe_Number, @PL_Recipe_Name, @PL_Portion_Size, @PL_Student_Portions_Planned, @PL_Adults_ALC__Portions_Planned,
@PL_Total__Portions_Planned, @PL_Factor_Portions, @DOC_Quantity_Of_Food_Used, @DOC_Portions_Prepared, @DOC_Portions_Brought_Forward, @DOC_Portions_Leftover,
@DOC_Leftover_Code, @DOC_Total_Portions_Served, @DOC_Portions_Served_Students, @DOC_Portions_Served_Adults_ALC, getdate())
end
      RETURN