Hi,
I am getting one error in code below. Please help.
System.FormatException: Failed to convert parameter value from a String to a Int32
Public Sub AddGrid()
For count As Integer = 0 To GD_Prod.Items.Count - 1
'getting the bound fields values
Dim str0 As String = GD_Prod.Items(count).Cells(0).Text
Dim str1 As String = GD_Prod.Items(count).Cells(1).Text
Dim str2 As String = GD_Prod.Items(count).Cells(2).Text
Dim str5 As String = GD_Prod.Items(count).Cells(5).Text
Dim str13 As String = GD_Prod.Items(count).Cells(13).Text
Dim str14 As String = GD_Prod.Items(count).Cells(14).Text
'getting the template fields value
Dim tx3 As TextBox = DirectCast(GD_Prod.Items(count).FindControl("TxtSTUPort"), TextBox)
Dim tx4 As TextBox = DirectCast(GD_Prod.Items(count).FindControl("TxtAAPort"), TextBox)
Dim tx6 As TextBox = DirectCast(GD_Prod.Items(count).FindControl("TxtFPort"), TextBox)
Dim tx7 As TextBox = DirectCast(GD_Prod.Items(count).FindControl("TxtQoFUsed"), TextBox)
Dim tx8 As TextBox = DirectCast(GD_Prod.Items(count).FindControl("TxtPPort"), TextBox)
Dim tx9 As TextBox = DirectCast(GD_Prod.Items(count).FindControl("TxtLOPort"), TextBox)
Dim tx10 As TextBox = DirectCast(GD_Prod.Items(count).FindControl("TxtBFPort"), TextBox)
Dim tx11 As DropDownList = DirectCast(GD_Prod.Items(count).FindControl("ddlLOCode"), DropDownList)
Dim tx12 As TextBox = DirectCast(GD_Prod.Items(count).FindControl("TxtTSPort"), TextBox)
'Dim tx15 As Label = DirectCast(FindControl("lblPKey"), Label)
'Dim str15 As String = (lblPKey.Text)
Dim strkey As String = Session("key").ToString
'inserting the template values
Dim str3 As String = (tx3.Text)
Dim str4 As String = (tx4.Text)
Dim str6 As String = (tx6.Text)
Dim str7 As String = (tx7.Text)
Dim str8 As String = (tx8.Text)
Dim str9 As String = (tx9.Text)
Dim str10 As String = (tx10.Text)
Dim str11 As String = (tx11.SelectedValue.ToString)
Dim str12 As String = (tx12.Text)
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("FNConnectionString").ConnectionString)
Dim cmd As New SqlCommand("P_FN_PR_InsertGridData", con)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@Pkey", SqlDbType.Char).Value = strkey
cmd.Parameters.Add("@PL_Recipe_Number", SqlDbType.Char).Value = str0
cmd.Parameters.Add("@PL_Recipe_Name", SqlDbType.Char).Value = str1
cmd.Parameters.Add("@PL_Portion_Size", SqlDbType.Char).Value = str2
cmd.Parameters.Add("@PL_Student_Portions_Planned", SqlDbType.Int).Value = str3
cmd.Parameters.Add("@PL_Adults_ALC__Portions_Planned", SqlDbType.Int).Value = str4
cmd.Parameters.Add("@PL_Total__Portions_Planned", SqlDbType.Int).Value = str5
cmd.Parameters.Add("@PL_Factor_Portions", SqlDbType.Char).Value = str6
cmd.Parameters.Add("@DOC_Quantity_Of_Food_Used", SqlDbType.Char).Value = str7
cmd.Parameters.Add("@DOC_Portions_Prepared ", SqlDbType.Int).Value = str8
cmd.Parameters.Add("@DOC_Portions_Brought_Forward ", SqlDbType.Int).Value = str9
cmd.Parameters.Add("@DOC_Portions_Leftover", SqlDbType.Int).Value = str10
cmd.Parameters.Add("@DOC_Leftover_Code", SqlDbType.Char).Value = str11
cmd.Parameters.Add("@DOC_Total_Portions_Served", SqlDbType.Int).Value = str12
cmd.Parameters.Add("@DOC_Portions_Served_Students", SqlDbType.Int).Value = str13
cmd.Parameters.Add("@DOC_Portions_Served_Adults_ALC", SqlDbType.Int).Value = str14
con.Open()
'cmd.ExecuteNonQuery()
Dim rows As Integer = cmd.ExecuteNonQuery
con.Close()
If rows = 1 Then
MsgBox("SUCCESS!")
Else
MsgBox("FAILED!")
End If
Next
End Sub
My Stored Proc is :
CREATE 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
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)
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)