Hi,
I am saving my grid data into sql database. But i getting error:
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Stack Trace:
Public Sub btnsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsave.Click
AddGrid()
End Sub
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("TxtLOPort"), TextBox)
Dim tx10 As TextBox = DirectCast(item.FindControl("TxtBFPort"), TextBox)
Dim tx11 As DropDownList = DirectCast(item.FindControl("ddlLOCode"), DropDownList)
Dim tx12 As TextBox = DirectCast(item.FindControl("TxtTSPort"), TextBox)
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.SelectedItem.Value)
Dim str12 As String = (tx12.Text)
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", Data.SqlDbType.Char)
cmd.Parameters("@Pkey").Value = lblPKey.Text.Trim
cmd.Parameters.Add("@PL_Recipe_Number", Data.SqlDbType.Char)
cmd.Parameters("@PL_Recipe_Number").Value = str0
cmd.Parameters.Add("@PL_Recipe_Name", Data.SqlDbType.Char)
cmd.Parameters("@PL_Recipe_Name").Value = str1
cmd.Parameters.Add("@PL_Portion_Size", Data.SqlDbType.Char)
cmd.Parameters("@PL_Portion_Size").Value = str2
cmd.Parameters.Add("@PL_Student_Portions_Planned", Data.SqlDbType.Int)
cmd.Parameters("@PL_Student_Portions_Planned").Value = str3
cmd.Parameters.Add("@PL_Adults_ALC__Portions_Planned", Data.SqlDbType.Int)
cmd.Parameters("@PL_Adults_ALC__Portions_Planned").Value = str4
cmd.Parameters.Add("@PL_Total__Portions_Planned", Data.SqlDbType.Int)
cmd.Parameters("@PL_Total__Portions_Planned").Value = str5
cmd.Parameters.Add("@PL_Factor_Portions", Data.SqlDbType.Char)
cmd.Parameters("@PL_Factor_Portions").Value = str6
cmd.Parameters.Add("@DOC_Quantity_Of_Food_Used", Data.SqlDbType.Char)
cmd.Parameters("@DOC_Quantity_Of_Food_Used").Value = str7
cmd.Parameters.Add("@DOC_Portions_Prepared ", Data.SqlDbType.Int)
cmd.Parameters("@DOC_Portions_Prepared ").Value = str8
cmd.Parameters.Add("@DOC_Portions_Brought_Forward ", Data.SqlDbType.Int)
cmd.Parameters("@DOC_Portions_Brought_Forward ").Value = str9
cmd.Parameters.Add("@DOC_Portions_Leftover", Data.SqlDbType.Int)
cmd.Parameters("@DOC_Portions_Leftover").Value = str10
cmd.Parameters.Add("@DOC_Leftover_Code", Data.SqlDbType.Char)
cmd.Parameters("@DOC_Leftover_Code").Value = str11
cmd.Parameters.Add("@DOC_Total_Portions_Served", Data.SqlDbType.Int)
cmd.Parameters("@DOC_Total_Portions_Served").Value = str12
cmd.Parameters.Add("@DOC_Portions_Served_Students", Data.SqlDbType.Int)
cmd.Parameters("@DOC_Portions_Served_Students").Value = str13
cmd.Parameters.Add("@DOC_Portions_Served_Adults_ALC", Data.SqlDbType.Int)
cmd.Parameters("@DOC_Portions_Served_Adults_ALC").Value = str14
con.Open()
cmd.ExecuteNonQuery ()
con.Close()
Next
End Sub
Stored Procedure:
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
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)
I am saving my grid data into sql database. But i getting error:
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
|
|
AddGrid()
End Sub
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("TxtLOPort"), TextBox)
Dim tx10 As TextBox = DirectCast(item.FindControl("TxtBFPort"), TextBox)
Dim tx11 As DropDownList = DirectCast(item.FindControl("ddlLOCode"), DropDownList)
Dim tx12 As TextBox = DirectCast(item.FindControl("TxtTSPort"), TextBox)
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.SelectedItem.Value)
Dim str12 As String = (tx12.Text)
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", Data.SqlDbType.Char)
cmd.Parameters("@Pkey").Value = lblPKey.Text.Trim
cmd.Parameters.Add("@PL_Recipe_Number", Data.SqlDbType.Char)
cmd.Parameters("@PL_Recipe_Number").Value = str0
cmd.Parameters.Add("@PL_Recipe_Name", Data.SqlDbType.Char)
cmd.Parameters("@PL_Recipe_Name").Value = str1
cmd.Parameters.Add("@PL_Portion_Size", Data.SqlDbType.Char)
cmd.Parameters("@PL_Portion_Size").Value = str2
cmd.Parameters.Add("@PL_Student_Portions_Planned", Data.SqlDbType.Int)
cmd.Parameters("@PL_Student_Portions_Planned").Value = str3
cmd.Parameters.Add("@PL_Adults_ALC__Portions_Planned", Data.SqlDbType.Int)
cmd.Parameters("@PL_Adults_ALC__Portions_Planned").Value = str4
cmd.Parameters.Add("@PL_Total__Portions_Planned", Data.SqlDbType.Int)
cmd.Parameters("@PL_Total__Portions_Planned").Value = str5
cmd.Parameters.Add("@PL_Factor_Portions", Data.SqlDbType.Char)
cmd.Parameters("@PL_Factor_Portions").Value = str6
cmd.Parameters.Add("@DOC_Quantity_Of_Food_Used", Data.SqlDbType.Char)
cmd.Parameters("@DOC_Quantity_Of_Food_Used").Value = str7
cmd.Parameters.Add("@DOC_Portions_Prepared ", Data.SqlDbType.Int)
cmd.Parameters("@DOC_Portions_Prepared ").Value = str8
cmd.Parameters.Add("@DOC_Portions_Brought_Forward ", Data.SqlDbType.Int)
cmd.Parameters("@DOC_Portions_Brought_Forward ").Value = str9
cmd.Parameters.Add("@DOC_Portions_Leftover", Data.SqlDbType.Int)
cmd.Parameters("@DOC_Portions_Leftover").Value = str10
cmd.Parameters.Add("@DOC_Leftover_Code", Data.SqlDbType.Char)
cmd.Parameters("@DOC_Leftover_Code").Value = str11
cmd.Parameters.Add("@DOC_Total_Portions_Served", Data.SqlDbType.Int)
cmd.Parameters("@DOC_Total_Portions_Served").Value = str12
cmd.Parameters.Add("@DOC_Portions_Served_Students", Data.SqlDbType.Int)
cmd.Parameters("@DOC_Portions_Served_Students").Value = str13
cmd.Parameters.Add("@DOC_Portions_Served_Adults_ALC", Data.SqlDbType.Int)
cmd.Parameters("@DOC_Portions_Served_Adults_ALC").Value = str14
con.Open()
cmd.ExecuteNonQuery ()
con.Close()
Next
End Sub
Stored Procedure:
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
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)