dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Input string was not in a correct format.error

  1. #1
    Join Date
    Feb 2004
    Posts
    126

    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

  2. #2
    Join Date
    May 2005
    Location
    UK
    Posts
    278
    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
    Sri

  3. #3
    Join Date
    Feb 2004
    Posts
    126
    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???

  4. #4
    Join Date
    May 2005
    Location
    UK
    Posts
    278
    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
    Sri

  5. #5
    Join Date
    May 2005
    Location
    UK
    Posts
    278
    I am sorry i am not sure about the VB syntax i gave you the equivalent C# code I guess
    Sri

  6. #6
    Join Date
    Dec 2003
    Posts
    2,750
    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.
    Paul
    ~~~~
    Microsoft MVP (Visual Basic)

  7. #7
    Join Date
    Feb 2004
    Posts
    126
    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!!!!

Similar Threads

  1. if statements
    By airrazor in forum Java
    Replies: 11
    Last Post: 11-06-2005, 11:18 AM
  2. Input string was not in a correct format.
    By ewarmour in forum ASP.NET
    Replies: 0
    Last Post: 03-27-2003, 02:36 PM
  3. Input string was not in a correct format
    By mdengler in forum ASP.NET
    Replies: 0
    Last Post: 11-26-2002, 03:32 PM
  4. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 0
    Last Post: 08-10-2000, 09:16 PM
  5. Deadlock error.. how to remove
    By Chandra in forum VB Classic
    Replies: 0
    Last Post: 06-22-2000, 12:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center