Solved

System.IndexOutOfRangeException: price

Posted on 2008-06-18
6
806 Views
Last Modified: 2008-06-18
Hi Experts

I hope some of you can assist me in this.
My webapplication (asp.net/c#) works like a charm on localhost. But when I put it out on the server I get a server error saying System.IndexOutOfRangeException: price
Highlighted piece of code: "string pris = rdrVarer["pris"].ToString().Replace(",0000", ".00");"

This happens when I click the button to move the items in the basket and place them in the orders table

Can anyone please point me in the right direction here because I don't know what to look for

This is the code behind for this particular button:
// move data from hk to orders
 

                    SqlCommand sqlHentvarer = new SqlCommand("select vare_id,cast(pris as numeric(10,2)),storrelse,antall from hk where session_id ='" + Session.SessionID + "'", sqlConn);
 

                    SqlDataReader rdrVarer = sqlHentvarer.ExecuteReader();
 

                    // make loop 
 

                    while (rdrVarer.Read())

                    {

                        // norwegian vs english configuration

 

                        string pris = rdrVarer["pris"].ToString().Replace(",0000", ".00");

                        
 

                        SqlCommand sqlSettinnOrdre = new SqlCommand("insert into ordrelinjer (ordre_id,vare_id,pris,storrelse,antall) values ("

                                                                + OrdreID + "," + rdrVarer["vare_id"] + "," + pris

                                                                + "," + rdrVarer["storrelse"] + rdrVarer["antall"] + ")", sqlConn);
 

                        sqlSettinnOrdre.ExecuteNonQuery();
 
 

                    }

Open in new window

0
Comment
Question by:Raggdog
6 Comments
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 21817713
it looks as though the database the server uses does not have the "pris" column.

are you connecting to the exact same database on your development machine and server?
0
 

Author Comment

by:Raggdog
ID: 21817733
yes... it is the exact same
0
 

Author Comment

by:Raggdog
ID: 21817931
I use the same database both on the server and localhost.
Why is there this works on localmachine - all orders are placed - and not on the server...?

Please people...
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 1

Expert Comment

by:horusmx
ID: 21818685
Hi girl, can you put more details, your stack trace for instance?
0
 
LVL 11

Accepted Solution

by:
anuragal earned 500 total points
ID: 21819087
Hi

Try mofify the query in your command statement

cast(pris as numeric(10,2)),

to this

cast(pris as numeric(10,2)) As pris,

Hope it works.

Anurag
0
 

Author Comment

by:Raggdog
ID: 21819462
@anuragal, thank you...  
It works like a charm..


Maya
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now