[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ASP.NET   -  Input string was not in a correct format problem

Posted on 2005-05-05
3
Medium Priority
?
436 Views
Last Modified: 2006-11-18
hi,

I have a  function:

Public Shared Function GetProducts() As SqlDataReader

        Dim connection As New SqlConnection(connectionString)
        Dim command As New SqlCommand("GetShoppingCartProducts", connection)
        command.CommandType = CommandType.StoredProcedure

        command.Parameters.Add("@CartID", SqlDbType.Char, 36)
        command.Parameters("@CartID").Value = shoppingCartID



        Try
            connection.Open()
            Return command.ExecuteReader(CommandBehavior.CloseConnection)

        Catch ex As Exception
            connection.Close()
            Throw ex


        End Try
    End Function


Which makes use of the variable (located in same class file):

  Private Shared ReadOnly Property shoppingCartID()
        Get
            Dim context As HttpContext = HttpContext.Current

            If context.Request.Cookies("Wind_CartID") Is Nothing Then
                Dim cartID As Guid = Guid.NewGuid()
                Dim cookie As New HttpCookie("Wind_CartID", cartID.ToString)
                Dim currentDate As DateTime = DateTime.Now
                Dim ts As New TimeSpan(10, 0, 0, 0)
                Dim expirationDate As DateTime = currentDate.Add(ts)
                cookie.Expires = expirationDate
                context.Response.Cookies.Add(cookie)
                Return cartID.ToString()

            Else
                Return context.Request.Cookies("Wind_CartID").Value
            End If
        End Get
    End Property



And which calls the stored procedure (in an sql database):

ALTER PROCEDURE ASPNET.GetShoppingCartProducts

      (
            @CartID char(36)
      )

AS
      SELECT Product.ProductID, Product.Name, Product.Price, ShoppingCart.Quantity, product.Price*ShoppingCart.Quantity As Subtotal
      From ShoppingCart INNER Join Product
      ON ShoppingCart.ProductID = Product.ProductID
      WHERE ShoppingCart.CartID = @CartID
      RETURN




When I run the function I get:


Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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

Source Error:


Line 43:             grid.DataSource = ShoppingCart.GetProducts
Line 44:             grid.DataKeyField = "ProductID"
Line 45:             grid.DataBind()
Line 46:         End If
Line 47:     End Sub
 

Source File: C:\myCommerceSite\WindAddict\UserControls\ShoppingCart.ascx.vb    Line: 45




Any help would be greatly appreciated.
Thanks,
Paul
0
Comment
Question by:PaulCampbell
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
bwh1te earned 1000 total points
ID: 13935913
Hi there,

Check your stored proc return results.

If your datagrid is using templates to render the output then I supsect you may have a NULL value being returned from the stored proc. The template dataitem cannot be NULL - hence the 'wrong format' section of the message.

Check all of your stored proc return values and add an ISNULL(columnname, replacevalue) check in the stored proc to ensure that a value gets passed back.
0
 
LVL 2

Author Comment

by:PaulCampbell
ID: 13936005
thanks a lot.

didn't realize sql was case sensitive!

0
 
LVL 1

Expert Comment

by:bwh1te
ID: 13936082
It can be case-sensitive or non-case-sensitive, it all depends on how the database is set up when it is created.

Some applications that use SQL need the case sensitivity option. Generally speaking though it is a right pain in the a***.

Glad to have helped.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question