System.FormatException: Input string was not in a correct format.????

Rate It (1)

Last post 09-15-2009 11:14 PM by chetan.sarode. 13 replies.

Sort Posts:

  • System.FormatException: Input string was not in a correct format.????

    01-23-2006, 9:10 PM
    • Member
      70 point Member
    • d1mann
    • Member since 01-24-2006, 2:01 AM
    • Posts 14

    The installation went fine, and is running ok on my localhost, I 'm clicking my way through the app and everything is working fine, until I try and run a report and I get:

    System.FormatException: Input string was not in a correct format

    Line 260:

    Line 261:            For Each str As String In substrings
    Line 262:                Dim id As Integer = CInt(str)
    Line 263:                list.Add(Project.GetProjectById(id))
    Line 264:            Next str
    Source File: C:\Inetpub\wwwroot\TimeTracker1\App_Code\BLL\Project.vb    Line: 262

    Have the same declaration at Line 307, but I don't know enough to understand how to reformat the string as it's passed in... Any suggestions?

    Dennis

  • Re: System.FormatException: Input string was not in a correct format.????

    01-24-2006, 12:02 AM
    • Member
      225 point Member
    • Jeevi
    • Member since 11-03-2005, 7:59 AM
    • Posts 54

    hi,

     this problem occurs when u try to convert non numeric or empty string into integer.add the following condition inside ur loop.

        For Each str As String In substrings

    IF isNumeric(str) THEN
         Dim id As Integer = CInt(str)                                                                                                   ENDIF
    :             list.Add(Project.GetProjectById(id))
        Next str

      

  • Re: System.FormatException: Input string was not in a correct format.????

    01-24-2006, 9:39 PM
    • Member
      70 point Member
    • d1mann
    • Member since 01-24-2006, 2:01 AM
    • Posts 14

    Thanks Jeevi, new to this, didn't think about passing a null value in... that validation statement fixed it!

     

  • Re: System.FormatException: Input string was not in a correct format.????

    12-14-2007, 5:09 PM
    • Member
      14 point Member
    • sabena248
    • Member since 12-11-2007, 4:20 PM
    • Posts 7

    I keep getting the same error.

    Line 324:                                                             ByRef oList As List(Of IPClass))
    Line 325:            Do While returnData.Read()
    Line 326:                Dim oItem As IPClass = New IPClass( _
    Line 327:                                               CStr(returnData("Device")), _
    Line 328:                                               CStr(returnData("Location")), _

  • Re: System.FormatException: Input string was not in a correct format.????

    12-14-2007, 10:38 PM

    Try to debug application & check the value

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: System.FormatException: Input string was not in a correct format.????

    02-04-2008, 10:26 PM

    Have you solved your problem what you are facing

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: System.FormatException: Input string was not in a correct format.????

    04-14-2008, 3:25 AM
    • Member
      2 point Member
    • Vinoo
    • Member since 04-14-2008, 7:23 AM
    • Posts 1

    Hi, I have a similar problem...I am getting System.FormatException: Input string was not in a correct format while converting string to int but the string is neither empty nor non numeric.... can someone plz help me...what can be the other reason for this exception...

  • Re: System.FormatException: Input string was not in a correct format.????

    08-13-2008, 11:25 PM

    Can you tell me what is the value of string

    http://support.microsoft.com/kb/942460

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: System.FormatException: Input string was not in a correct format.????

    09-08-2008, 11:30 PM

    If you solved the problem, Please mark the answer

    So it will help for other people

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: System.FormatException: Input string was not in a correct format.????

    09-07-2009, 6:10 AM
    • Member
      20 point Member
    • aduhperf
    • Member since 03-18-2009, 12:21 PM
    • Posts 52

    please i having similar problem app breaks at this line in the code

    int howManyProducts = Convert.ToInt32(comm.Parameters["@HowManyProducts"].Value.ToString());

    the complete code is

    public static DataTable GetProductsOnDeptPromo

    (string departmentId, string pageNumber, out int howManyPages)

    {

    // get a configured DbCommand object

    DbCommand comm = GenericDataAccess.CreateCommand();

    // set the stored procedure name

    comm.CommandText = "CatalogGetProductsOnDeptPromo";

    // create a new parameter

    DbParameter param = comm.CreateParameter();

    param.ParameterName = "@DepartmentID";

    param.Value = departmentId;

    param.DbType = DbType.Int32;

    comm.Parameters.Add(param);

    // create a new parameter

    param = comm.CreateParameter();

    param.ParameterName = "@DescriptionLength";

    param.Value = BalloonShopConfiguration.ProductDescriptionLength;

    param.DbType = DbType.Int32;

    comm.Parameters.Add(param);

    // create a new parameter

    param = comm.CreateParameter();

    param.ParameterName = "@PageNumber";

    param.Value = pageNumber;

    param.DbType = DbType.Int32;

    comm.Parameters.Add(param);

    // create a new parameter

    param = comm.CreateParameter();

    param.ParameterName = "@ProductsPerPage";

    param.Value = BalloonShopConfiguration.ProductsPerPage;

    param.DbType = DbType.Int32;

    comm.Parameters.Add(param);

    // create a new parameter

    param = comm.CreateParameter();

    param.ParameterName = "@HowManyProducts";

    param.Direction = ParameterDirection.Output;

    param.DbType = DbType.Int32;

    comm.Parameters.Add(param);

    // execute the stored procedure and save the results in a DataTable

    DataTable table = GenericDataAccess.ExecuteSelectCommand(comm);

    // calculate how many pages of products and set the out parameter

    int howManyProducts = Convert.ToInt32(comm.Parameters["@HowManyProducts"].Value.ToString());

        

    howManyPages = (int)Math.Ceiling((double)howManyProducts /

    (double)BalloonShopConfiguration.ProductsPerPage);

    // return the page of products

    return table;


    (string departmentId, string pageNumber, out int howManyPages)
    {
    // get a configured DbCommand object
    DbCommand comm = GenericDataAccess.CreateCommand();
    // set the stored procedure name
    comm.CommandText = "CatalogGetProductsOnDeptPromo";
    // create a new parameter
    DbParameter param = comm.CreateParameter();
    param.ParameterName = "@DepartmentID";
    param.Value = departmentId;
    param.DbType = DbType.Int32;
    comm.Parameters.Add(param);
    // create a new parameter
    param = comm.CreateParameter();
    param.ParameterName = "@DescriptionLength";
    param.Value = BalloonShopConfiguration.ProductDescriptionLength;
    param.DbType = DbType.Int32;
    comm.Parameters.Add(param);
    // create a new parameter
    param = comm.CreateParameter();
    param.ParameterName = "@PageNumber";
    param.Value = pageNumber;
    param.DbType = DbType.Int32;
    comm.Parameters.Add(param);
    // create a new parameter
    param = comm.CreateParameter();
    param.ParameterName = "@ProductsPerPage";
    param.Value = BalloonShopConfiguration.ProductsPerPage;
    param.DbType = DbType.Int32;
    comm.Parameters.Add(param);
    // create a new parameter
    param = comm.CreateParameter();
    param.ParameterName = "@HowManyProducts";
    param.Direction = ParameterDirection.Output;
    param.DbType = DbType.Int32;
    comm.Parameters.Add(param);
    // execute the stored procedure and save the results in a DataTable
    DataTable table = GenericDataAccess.ExecuteSelectCommand(comm);
    // calculate how many pages of products and set the out parameter
    int howManyProducts = Convert.ToInt32(comm.Parameters["@HowManyProducts"].Value.ToString());
        
    howManyPages = (int)Math.Ceiling((double)howManyProducts /
    (double)BalloonShopConfiguration.ProductsPerPage);
    // return the page of products
    return table;
    }public static DataTable GetProductsOnDeptPromo
    (string departmentId, string pageNumber, out int howManyPages)
    {
    // get a configured DbCommand object
    DbCommand comm = GenericDataAccess.CreateCommand();
    // set the stored procedure name
    comm.CommandText = "CatalogGetProductsOnDeptPromo";
    // create a new parameter
    DbParameter param = comm.CreateParameter();
    param.ParameterName = "@DepartmentID";
    param.Value = departmentId;
    param.DbType = DbType.Int32;
    comm.Parameters.Add(param);
    // create a new parameter
    param = comm.CreateParameter();
    param.ParameterName = "@DescriptionLength";
    param.Value = BalloonShopConfiguration.ProductDescriptionLength;
    param.DbType = DbType.Int32;
    comm.Parameters.Add(param);
    // create a new parameter
    param = comm.CreateParameter();
    param.ParameterName = "@PageNumber";
    param.Value = pageNumber;
    param.DbType = DbType.Int32;
    comm.Parameters.Add(param);
    // create a new parameter
    param = comm.CreateParameter();
    param.ParameterName = "@ProductsPerPage";
    param.Value = BalloonShopConfiguration.ProductsPerPage;
    param.DbType = DbType.Int32;
    comm.Parameters.Add(param);
    // create a new parameter
    param = comm.CreateParameter();
    param.ParameterName = "@HowManyProducts";
    param.Direction = ParameterDirection.Output;
    param.DbType = DbType.Int32;
    comm.Parameters.Add(param);
    // execute the stored procedure and save the results in a DataTable
    DataTable table = GenericDataAccess.ExecuteSelectCommand(comm);
    // calculate how many pages of products and set the out parameter
    int howManyProducts = Convert.ToInt32(comm.Parameters["@HowManyProducts"].Value.ToString());
        
    howManyPages = (int)Math.Ceiling((double)howManyProducts /
    (double)BalloonShopConfiguration.ProductsPerPage);
    // return the page of products
    return table;
    }

  • Re: System.FormatException: Input string was not in a correct format.????

    09-07-2009, 6:34 AM
    • Member
      338 point Member
    • ShilpaSunil
    • Member since 08-17-2009, 9:11 AM
    • Posts 95

    Again u r getting null value i think

    by default in stored procedure , if @HowManyProducts count is 0, u set @HowManyProducts to zero,


    oterwise use iif() condition to check where null or not , after that u convert it.



  • Re: System.FormatException: Input string was not in a correct format.????

    09-07-2009, 7:01 AM
    • Member
      20 point Member
    • aduhperf
    • Member since 03-18-2009, 12:21 PM
    • Posts 52

    thanks for ur response. But please i still dont ge itt. cud  u explain it wit some  lines of code. thanks

  • Re: System.FormatException: Input string was not in a correct format.????

    09-07-2009, 2:30 PM
    • Member
      20 point Member
    • aduhperf
    • Member since 03-18-2009, 12:21 PM
    • Posts 52

    I have gotten the solutions i figured dat that the @HowManyProducts was returning null values

    so wat i did was check for isnull using 

     SELECT @HowManyProducts = isNull (COUNT (ProductID), 0) FROM @Products

  • Re: System.FormatException: Input string was not in a correct format.????

    09-15-2009, 11:14 PM

     Thats nice

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
Page 1 of 1 (14 items)