System.IndexOutOfRangeException: price

Hi Experts

I hope some of you can assist me in this.
My webapplication ( 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);

Open in new window

Who is Participating?
Anurag AgarwalConnect With a Mentor Python DeveloperCommented:

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.

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?
RaggdogAuthor Commented:
yes... it is the exact same
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

RaggdogAuthor Commented:
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...
Hi girl, can you put more details, your stack trace for instance?
RaggdogAuthor Commented:
@anuragal, thank you...  
It works like a charm..

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.