Solved

System.IndexOutOfRangeException: price

Posted on 2008-06-18
6
814 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
Independent Software Vendors: 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 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

749 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