Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# Shopping Cart Error( Value conversion)

Status
Not open for further replies.

PNeems

Programmer
May 17, 2008
19
US
I am writing a shopping cart using C# and I have got a good portion of it down, being able to add a users values to the cart and storing a unique identifier per user on the DB to that users only get their cart. I am getting and issue when it comes to viewing that cart.
This is the error I get

Exception Details: System.FormatException: String was not recognized as a valid Boolean.

Source Error: occurs on line 28


Line 26: this.Title = NYCTEESConfiguration.SiteName + " : Shopping Cart";
Line 27: // get the items in the shopping cart
Line 28: DataTable dt = ShoppingCartAccess.GetItems();
Line 29: // if the shopping cart is empty...
Line 30: if (dt.Rows.Count == 0)


Here is my shopping cart access call
public static DataTable GetItems()
{
// get a configured DbCommand object
DbCommand comm = GenericDataAccess.CreateCommand();
// set the stored procedure name
comm.CommandText = "ShoppingCartGetItems";
// create a new parameter
DbParameter param = comm.CreateParameter();
param.ParameterName = "@CARTID";
param.Value = shoppingCartId;
param.DbType = DbType.String;
param.Size = 36;
comm.Parameters.Add(param);
// return the result table
DataTable table = GenericDataAccess.ExecuteSelectCommand(comm);
return table;
}

I know the database call and the paramters all must work becuase i use the exact same commands on the insert portion which works. I tested the stored procedure i call and it works as well. I am not sure why it is looking for a valid Boolean, i never asked it to look for one, i just want it to look at the data table.

I know this is alot, but anyone who could help would be GREATLY appreciated. Thanks so much
 
somewhere in your code you are try to parse a string as a boolean. if you use unit tests either your missing a coverage case, or at least 1 test is failing.

if your manually debugging your code set a break point and step through the code so see where the exception is thrown.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I am not sure I follow. I dont see how there is a Parsing error anywhere. The only time i Parse in my ENTIRE code is to determine a boolean value in an XML String which reads "true" but that is completely unrelated to this and the site build correctly when i load the other pages just not the "shopping cart page" The error comes on the DataTable line, but i dont see how that is trying to be formated at all. You can see it created in the code above.

Is there something i am missing with datatables?
 
Exception Details: System.FormatException: String was not recognized as a valid Boolean.

Now do you see how there is a parsing error somewhere?

I would bet that you have your boolean value as "True" and "False", whereas to be parsed to a boolean they must be "true" and "false". Try forcing it to lowercase before you cast. Or better yet storing it in lowercase in your xml :)

Hope this helps,

Alex

[small]----signature below----[/small]
Majority rule don't work in mental institutions

My Crummy Web Page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top