473,394 Members | 1,722 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,394 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 10736
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.