using System; using System.Data; using System.Data.Odbc; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class Multiplication : System.Web.UI.Page { public string[] scores = new string[14]; int loop, idx; string[] strScore = new string[2]; string strFull, strURI = ""; protected void Page_Load(object sender, EventArgs e) { // There is a user logged in. if ((string)Session["user"] != "" && Session["user"] != null) { string strSql; // populate the array of table element names. for (loop = 0; loop < 13; loop++) scores[loop] = "Times" + loop.ToString(); // and the last one. scores[13] = "TimesAll"; // Create the DB connection. OdbcConnection conn = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); OdbcCommand cmd = new OdbcCommand(); cmd.Connection = conn; // if we are coming from the Results.aspx page, write the results to the db. if (Request.UrlReferrer != null) { strURI = Request.UrlReferrer.ToString(); if (strURI.Contains("Results.aspx")) { strFull = Request.Form["txtTest2"]; strScore = strFull.Split(','); // create the sql command to write the data. strSql = "UPDATE UserData SET " + strScore[0] + "='" + strScore[1] + "' WHERE UserID = '" + Session["user"] + "'"; conn.Open(); cmd.CommandText = strSql; cmd.ExecuteNonQuery(); conn.Close(); } } // Get the data based on the user. strSql = "SELECT * FROM UserData WHERE UserID = '" + Session["user"] + "'"; cmd.CommandText = strSql; OdbcDataReader rdr; conn.Open(); rdr = cmd.ExecuteReader(); if (rdr.HasRows == true) for (loop = 0; loop < 14; loop++) { scores[loop] = rdr[scores[loop]].ToString(); } rdr.Close(); conn.Close(); } // end if } }