?
Solved

System.IndexOutOfRangeException: price

Posted on 2008-06-18
6
Medium Priority
?
823 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

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.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

762 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