473,698 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Index was outside the bounds of the array" on Add

kim
Scenario (I'm a newbie): I have a datagrid with countries
listed and 5 parameters in each row. I want to add a row
to this datagrid via an Event Handler. Very basic stuff.
This method then call a Business method, which calls a
Data method which calls an SP in MS SQL.

My code compiles well, but the page throws "Index was
outside the bounds of the array". I really can't figure
why, take a look maybe you pros see can read between the
lines:

----- .apsx page:

protected void AddNew_Click(ob ject sender, EventArgs e)
{
if (Page.IsValid)
{
//convert to Int
int milobs =
Convert.ToInt32 (NewContribMilo bs.Text);
int contingent =
Convert.ToInt32 (NewContribCont ingent.Text);

Business.Contri bCountry
contribCountry = new Business.Contri bCountry();
//SiteIdentity currUser =
(SiteIdentity)C ontext.User.Ide ntity;

// add the new record
contribCountry. Create
(NewContribCoun try.Text.Trim() , NewContribPays. Text.Trim
(), milobs, contingent, currUser.UserID ).Visible = true;

ShowAddNewContr ols(false);
BindGrid();
}
}

---- business class:
// create a new record
public int Create(string country, string
pays, int milobs, int contingent, int userID)
{
Data.Military military = new
Data.Military(s ettings.Connect ionString);
countryID = military.Add(co untry,
pays, milobs, contingent, userID);
return countryID;
}

---- data class:
// add a military
public int Add(string country, string
pays, int milobs, int contingent, int userID)
{
int numAffected;

// create the parameters
SqlParameter[] parameters = {

new SqlParameter
("@Country", SqlDbType.VarCh ar, 25),

new SqlParameter("@ Pays",
SqlDbType.VarCh ar, 25),

new SqlParameter
("@Milobs", SqlDbType.Int, 4),

new SqlParameter
("@Contingen t", SqlDbType.Int, 4),

new SqlParameter
("@UserID", SqlDbType.Int, 4)

};

// set the values
parameters[0].Value = country.Trim
();
parameters[1].Value = pays.Trim();
parameters[2].Value = milobs;
parameters[3].Value = contingent;
parameters[4].Value = userID;
parameters[5].Direction =
ParameterDirect ion.Output;

RunProcedure
("sp_Contributi ons_Military_In sert", parameters, out
numAffected);

return (int)parameters[5].Value;
}

---- end

Thanks in advance for any help.

Jul 19 '05 #1
1 10774
It would be very helpful if you told us which line of code throws the error.

"kim" <ki********@yah oo.com> wrote in message
news:01******** *************** *****@phx.gbl.. .
Scenario (I'm a newbie): I have a datagrid with countries
listed and 5 parameters in each row. I want to add a row
to this datagrid via an Event Handler. Very basic stuff.
This method then call a Business method, which calls a
Data method which calls an SP in MS SQL.

My code compiles well, but the page throws "Index was
outside the bounds of the array". I really can't figure
why, take a look maybe you pros see can read between the
lines:

----- .apsx page:

protected void AddNew_Click(ob ject sender, EventArgs e)
{
if (Page.IsValid)
{
//convert to Int
int milobs =
Convert.ToInt32 (NewContribMilo bs.Text);
int contingent =
Convert.ToInt32 (NewContribCont ingent.Text);

Business.Contri bCountry
contribCountry = new Business.Contri bCountry();
//SiteIdentity currUser =
(SiteIdentity)C ontext.User.Ide ntity;

// add the new record
contribCountry. Create
(NewContribCoun try.Text.Trim() , NewContribPays. Text.Trim
(), milobs, contingent, currUser.UserID ).Visible = true;

ShowAddNewContr ols(false);
BindGrid();
}
}

---- business class:
// create a new record
public int Create(string country, string
pays, int milobs, int contingent, int userID)
{
Data.Military military = new
Data.Military(s ettings.Connect ionString);
countryID = military.Add(co untry,
pays, milobs, contingent, userID);
return countryID;
}

---- data class:
// add a military
public int Add(string country, string
pays, int milobs, int contingent, int userID)
{
int numAffected;

// create the parameters
SqlParameter[] parameters = {

new SqlParameter
("@Country", SqlDbType.VarCh ar, 25),

new SqlParameter("@ Pays",
SqlDbType.VarCh ar, 25),

new SqlParameter
("@Milobs", SqlDbType.Int, 4),

new SqlParameter
("@Contingen t", SqlDbType.Int, 4),

new SqlParameter
("@UserID", SqlDbType.Int, 4)

};

// set the values
parameters[0].Value = country.Trim
();
parameters[1].Value = pays.Trim();
parameters[2].Value = milobs;
parameters[3].Value = contingent;
parameters[4].Value = userID;
parameters[5].Direction =
ParameterDirect ion.Output;

RunProcedure
("sp_Contributi ons_Military_In sert", parameters, out
numAffected);

return (int)parameters[5].Value;
}

---- end

Thanks in advance for any help.

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2757
by: Eugene | last post by:
Hello all, I've been trying to figure this out for a few days now, and still have no clue what's going on... I have a few related tables in MS Access (Clients, Cars, Sales), and a datagrid, binded to dataview. Here's a catch - whenever I select a client, and then find a car which belongs to this client, and click on empty space in datagrid (that is in gray area below rows) - I get "Index was outside the bounds of the array" error......
1
3553
by: melinda | last post by:
How do you set up a MDI interface so that one of the MDI forms can be dragged outside of the parent form. For example, in Visual Studio, you can do this with some of the windows. Is this MDI? Or how do you that in C#.net?
0
1297
by: Trapulo | last post by:
I've a datagrid filled with a collection of objects that inherits from basecollection. When I remove an item from this collection and then click onto the datagrid, I've always this error: "Index was outside the bounds of the array datagrid" I've tried this structure: Dim oldList As Business.MyBaseCollection = DirectCast(dgDetails.DataSource,
4
3606
by: Antoine | last post by:
Herfried and Cor:- I used tracing and actually tracked down the code that was causing the problem most likely. I wonder if you wanted to comment on it. Also I wonder if there is a better way of testing if there is data than testing the length of the xml string I used as stringreader to create the dataset, but thats a side issue. I think I tried isdbnull and is nothing and stuff like that and they cause
1
308
by: kim | last post by:
Scenario (I'm a newbie): I have a datagrid with countries listed and 5 parameters in each row. I want to add a row to this datagrid via an Event Handler. Very basic stuff. This method then call a Business method, which calls a Data method which calls an SP in MS SQL. My code compiles well, but the page throws "Index was outside the bounds of the array". I really can't figure why, take a look maybe you pros see can read between the...
3
3159
by: writebrent | last post by:
I wrote a little interface for users to post data to a website. On their local machines, it produces CSV from an Excel spreadsheet, then posts it to the site. In some cases, the CSV will contain ampersands. For example, abc,American & British Company,1,4.34,5 ded,Dog Eat Dog,2,6.3,5.766 The code on the site is pretty standard: it loops through an array of lines from the CSV split on line ends, and then loops through another
15
4472
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about enased whitespace (to my best memory) AT other times I get an undefined index notice as below: Notice: Undefined index: last_reminder_id in...
5
7364
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : $http_ref= $HTTP_REFERER; $prog = $_COOKIE;
3
2088
by: kalaivani572 | last post by:
i am getting "Index was outside the bounds of the array." error when i try to get the checked items from list view. the code is private void btnFinish_Click(object sender, EventArgs e) { WaitCallback async = new WaitCallback(Executefeed); ThreadPool.QueueUserWorkItem(async, alParams); waitBar.ShowDialog(); }
0
8678
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9166
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.