fizzled
Regular
The code at the end of this post produces the error "Input string was not in a correct format" on the line with:
If I remove the Convert.ToInt32() method, the code will produce a compilation error saying "The best overloaded method match for 'ASP.rostatcalc_aspx.LoadWeapon(int)' has some invalid arguments".
I've checked the HTML produced by this template with the offending lines commented out and all the listbox values contain numbers, so I'm at a loss as to why this function call refuses to accept the input. Does anyone here know?
Code:
LoadWeaponList(Convert.ToInt32(lstJobs.SelectedValue));
If I remove the Convert.ToInt32() method, the code will produce a compilation error saying "The best overloaded method match for 'ASP.rostatcalc_aspx.LoadWeapon(int)' has some invalid arguments".
I've checked the HTML produced by this template with the offending lines commented out and all the listbox values contain numbers, so I'm at a loss as to why this function call refuses to accept the input. Does anyone here know?
Code:
private String strConnString;
private String strErrors;
public ROCharacter objCharacter;
public void Page_Load (Object Sender, EventArgs e) {
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("data/firo.mdb") + ";";
strErrors = "";
if (!Page.IsPostBack) {
objCharacter = new ROCharacter();
objCharacter.ConnString = strConnString;
LoadJobList();
LoadWeaponList(Convert.ToInt32(lstJobs.SelectedValue));
}
DisplayCharacterInformation();
} // End Page_Load
private void LoadJobList () {
String qryJobList = "SELECT JobID, JobName FROM Jobs ORDER BY JobName ASC;";
OleDbConnection cnJobs = new OleDbConnection(strConnString);
OleDbCommand cmdJobs = new OleDbCommand(qryJobList, cnJobs);
OleDbDataReader rdrJobs;
cnJobs.Open();
rdrJobs = cmdJobs.ExecuteReader();
if (rdrJobs.HasRows) {
lstJobs.DataSource = rdrJobs;
lstJobs.DataTextField = "JobName";
lstJobs.DataValueField = "JobID";
lstJobs.DataBind();
} else {
strErrors += "Could not load Job list from database.<br/>";
}
rdrJobs.Close();
rdrJobs = null;
cmdJobs = null;
cnJobs.Close();
cnJobs = null;
} // End LoadJobList
private void lstJobs_SelectedIndexChanged (Object Sender, EventArgs e) {
/* User selected a new Job for their Character. */
// LoadWeaponList(lstJobs.SelectedValue);
} // End lstJobs_SelectedIndexChanged
private void LoadWeaponList (int iJob) {
/* Load the Weapon Class list based on the specified Job. */
String qryWeapons = "SELECT JW.WeaponClassID, WC.WeaponClass FROM JobWeapons AS JW LEFT JOIN WeaponClasses AS WC ON JW.WeaponClassID = WC.WeaponClassID WHERE JW.JobID = @JobID ORDER BY WC.WeaponClass;";
OleDbConnection cnWeapons = new OleDbConnection(strConnString);
OleDbCommand cmdWeapons = new OleDbCommand(qryWeapons, cnWeapons);
OleDbDataReader rdrWeapons;
cmdWeapons.Parameters.Add(new OleDbParameter("JobID", OleDbType.Integer)).Value = lstJobs.SelectedValue;
cnWeapons.Open();
rdrWeapons = cmdWeapons.ExecuteReader();
if (rdrWeapons.HasRows) {
lstWeaponClasses.DataSource = rdrWeapons;
lstWeaponClasses.DataTextField = "WeaponClass";
lstWeaponClasses.DataValueField = "WeaponClassID";
lstWeaponClasses.DataBind();
} else {
strErrors += "Could not load Weapon Class list from database.<br/>";
}
rdrWeapons.Close();
rdrWeapons = null;
cmdWeapons = null;
cnWeapons.Close();
cnWeapons = null;
} // End LoadWeaponList