Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Input string was not in a correct format.error

i'm updating some filelds in the Datagid but i get the error:-
Input string was not in a correct format.
on the line " DBCommand.ExecuteNonQuery()"
Any ideas what 'm doing wrong could it be the FLOAT and Money datatypes
Thanks

'DBConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnStr"))
Dim DBCommand As SqlCommand = New SqlCommand("prMonthlyTargetsUpdateRecord", myConnection)

'Dim DBCommand As SqlCommand = New SqlCommand("UPDATE CMRC_Users SET FullName = @Name, EmailAddress = @Email, Password = @Pwd WHERE UserID = @UserID", DBConnection)

DBCommand.CommandType = CommandType.StoredProcedure

'DBCommand.Parameters.Add(New SqlParameter("@UserID", location.Text))
DBCommand.Parameters.Add(New SqlParameter("@year", SqlDbType.Int, 4)).Value = yr.text
DBCommand.Parameters.Add(New SqlParameter("@month", SqlDbType.Int, 4)).Value = mnth.text
DBCommand.Parameters.Add(New SqlParameter("@territory_code", SqlDbType.VarChar, 10)).Value = ter_code.text

DBCommand.Parameters.Add(New SqlParameter("@GP_target", SqlDbType.Money, 8)).Value = gp_target.text

DBCommand.Parameters.Add(New SqlParameter("@New_Connections_target", SqlDbType.Int, 4)).Value = conn_target.text
DBCommand.Parameters.Add(New SqlParameter("@Upgrade_Connections_target", SqlDbType.Int, 4)).Value = uograde_conn_target.text
DBCommand.Parameters.Add(New SqlParameter("@FTE", SqlDbType.Float, 8)).Value = fte.text

DBCommand.Parameters.Add(New SqlParameter("@PlansGT80", SqlDbType.Int, 4)).Value = plans.Text
DBCommand.Parameters.Add(New SqlParameter("@Foxtel", SqlDbType.Int, 4)).Value = foxtel.text
DBCommand.Parameters.Add(New SqlParameter("@Broadband", SqlDbType.Int, 4)).Value = broadband.text
DBCommand.Parameters.Add(New SqlParameter("@PrePaidPhones", SqlDbType.Int, 4)).Value = PrePaidPhones.text

DBCommand.Parameters.Add(New SqlParameter("@PrePaidRecharge", SqlDbType.Int, 4)).Value = PrePaidRecharge.text

DBCommand.Parameters.Add(New SqlParameter("@OutrightPhones", SqlDbType.Int, 4)).Value = OutrightPhones.text

DBCommand.Parameters.Add(New SqlParameter("@HandsetInsurance", SqlDbType.Int, 4)).Value = HandsetInsurance.text
DBCommand.Parameters.Add(New SqlParameter("@GenuineAccessory", SqlDbType.Int, 4)).Value = GenuineAccessory.text

DBCommand.Parameters.Add(New SqlParameter("@EBIT", SqlDbType.Float, 8)).Value = EBIT.Text
DBCommand.Parameters.Add(New SqlParameter("@StoreType", SqlDbType.VarChar, 10)).Value = "rote"

DBCommand.Parameters.Add(New SqlParameter("@StoreAtRisk", SqlDbType.Float, 8)).Value = StoreAtRisk.Text

myConnection.Open()
DBCommand.ExecuteNonQuery()
myConnection.Close()
MyDataGrid.EditItemIndex = -1
MyDataGrid.DataBind()
GetData()

My Stor_proc is:-

@year int,
@month int,
@territory_code varchar(10),
@GP_target money,
@New_Connections_target int,
@Upgrade_Connections_target int,
@FTE float,
@PlansGT80 int,
@Foxtel int,
@Broadband int,
@PrePaidPhones int,
@PrePaidRecharge int,
@OutrightPhones int,
@HandsetInsurance int,
@GenuineAccessory int,
@EBIT float,
@StoreType varchar(10),
@StoreAtRisk float,
@Status varchar(200) OUTPUT

AS

-- Check if entry already exits
if not exists (Select 1
From dbo.MonthlyTargetsBak mt
Where mt.theyear = @year and mt.TheMonth = @month and mt.Territory_Code = @Territory_Code)
begin
set @Status = 'Entry does not exist to update'
return
end

if not exists (Select 1
From dbo.Location
Where Territory_Code = @Territory_Code)
begin
set @Status = 'Location Not Found'
return
end

update MonthlyTargetsBak
set GP_target = @GP_target,
New_Connections_target = @New_Connections_target,
Upgrade_Connections_target = @Upgrade_Connections_target,
FTE = @FTE,
PlansGT80 = @PlansGT80,
Foxtel = @Foxtel,
Broadband = @Broadband,
PrePaidPhones = @PrePaidPhones,
PrePaidRecharge = @PrePaidRecharge,
OutrightPhones = @OutrightPhones,
HandsetInsurance = @HandsetInsurance,
GenuineAccessory = @GenuineAccessory,
EBIT = @EBIT,
StoreType = @StoreType,
StoreAtRisk = @StoreAtRisk
where theyear = @year
and TheMonth = @month
and Territory_Code = @Territory_Code

print cast(@@rowcount as varchar)
set @Status = 'Record Updated'
return @@rowcount
GO
[4687 byte] By [naijacoder] at [2007-11-11 7:14:36]
# 1 Re: Input string was not in a correct format.error
Why is it that there is no SqlParameter @Status added to your command object as an output type parameter, and yes I think it would make sense to parse the string before assigning it to a float equivalent to double and for money I am not sure in .Net check it out
srinivas_s at 2007-11-11 23:13:59 >
# 2 Re: Input string was not in a correct format.error
srinivas_s thx for the reply,
But when you say to parse the string before assigning it to a float equivalent to double and for money .
Do you mean Cstr(fte.text) for example?
naijacoder at 2007-11-11 23:14:54 >
# 3 Re: Input string was not in a correct format.error
You were assiging the input of your textbox directly to the parameter and hence i said use System.Double.Parse(overloaded methods available) to ensure a validation kind of thing happens,Do something for the money similarly by parsing it into a equivalent .net type MSDN has a reference of .Net types = sqltypes
srinivas_s at 2007-11-11 23:15:53 >
# 4 Re: Input string was not in a correct format.error
I am sorry i am not sure about the VB syntax i gave you the equivalent C# code I guess
srinivas_s at 2007-11-11 23:16:52 >
# 5 Re: Input string was not in a correct format.error
Not sure which parameter may be causing this error but I would work on identifying that first. Just remove parameters (one at a time) from both your code and stored procedure until the code executes w/out an error. Once you identify the parameter that is causing the problem you can determine why.
pclement at 2007-11-11 23:18:02 >
# 6 Re: Input string was not in a correct format.error
Thx guys for the reply.
But fixed it(i had to check for NULLS and also there was some data in the fields already wasn't well done since the data was imported from Excel). arg!!!!
naijacoder at 2007-11-11 23:19:01 >