K
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.
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.