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

  • Question

  • User412675671 posted

    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

    Monday, January 23, 2006 9:10 PM

All replies

  • User-692102023 posted

    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

      

    Tuesday, January 24, 2006 12:02 AM
  • User412675671 posted

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

     

    Tuesday, January 24, 2006 9:39 PM
  • User-1150202141 posted

    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")), _

    Friday, December 14, 2007 5:09 PM
  • User555306248 posted

    Try to debug application & check the value

    Friday, December 14, 2007 10:38 PM
  • User555306248 posted

    Have you solved your problem what you are facing

    Monday, February 4, 2008 10:26 PM
  • User-909197196 posted

    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...

    Monday, April 14, 2008 3:25 AM
  • User555306248 posted

    Can you tell me what is the value of string

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

    Wednesday, August 13, 2008 11:25 PM
  • User555306248 posted

    If you solved the problem, Please mark the answer

    So it will help for other people

    Monday, September 8, 2008 11:30 PM
  • User613417595 posted

    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;
    }

    Monday, September 7, 2009 6:10 AM
  • User-871326327 posted

    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.



    Monday, September 7, 2009 6:34 AM
  • User613417595 posted

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

    Monday, September 7, 2009 7:01 AM
  • User613417595 posted

    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

    Monday, September 7, 2009 2:30 PM
  • User555306248 posted

     Thats nice

    Tuesday, September 15, 2009 11:14 PM