473,326 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

"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(object sender, EventArgs e)
{
if (Page.IsValid)
{
//convert to Int
int milobs =
Convert.ToInt32(NewContribMilobs.Text);
int contingent =
Convert.ToInt32(NewContribContingent.Text);

Business.ContribCountry
contribCountry = new Business.ContribCountry();
//SiteIdentity currUser =
(SiteIdentity)Context.User.Identity;

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

ShowAddNewControls(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(settings.ConnectionString);
countryID = military.Add(country,
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.VarChar, 25),

new SqlParameter("@Pays",
SqlDbType.VarChar, 25),

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

new SqlParameter
("@Contingent", 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 =
ParameterDirection.Output;

RunProcedure
("sp_Contributions_Military_Insert", parameters, out
numAffected);

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

---- end

Thanks in advance for any help.

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

"kim" <ki********@yahoo.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(object sender, EventArgs e)
{
if (Page.IsValid)
{
//convert to Int
int milobs =
Convert.ToInt32(NewContribMilobs.Text);
int contingent =
Convert.ToInt32(NewContribContingent.Text);

Business.ContribCountry
contribCountry = new Business.ContribCountry();
//SiteIdentity currUser =
(SiteIdentity)Context.User.Identity;

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

ShowAddNewControls(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(settings.ConnectionString);
countryID = military.Add(country,
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.VarChar, 25),

new SqlParameter("@Pays",
SqlDbType.VarChar, 25),

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

new SqlParameter
("@Contingent", 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 =
ParameterDirection.Output;

RunProcedure
("sp_Contributions_Military_Insert", 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
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,...
1
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? ...
0
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: ...
4
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...
1
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...
3
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...
15
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...
5
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 : ...
3
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) {...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.