Solved

System.IndexOutOfRangeException: price

Posted on 2008-06-18
6
819 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

 
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:
Anurag Agarwal 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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

726 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