?
Solved

System.IndexOutOfRangeException: price

Posted on 2008-06-18
6
Medium Priority
?
830 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
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…

864 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