9/24/09

Storing the questions data in the temporary array

Its obvious that before getting answers we need to store them somethere.
I did it in the beginning of users_Default Page class
//to store all the questions
private static List<cQuestion> Questions=new List<cQuestion>();



cQuestion class have all question data including all the answers(options)

The interesting thing is, that even after clicking button and raising postback event the contents of this listarray are still in memory- the consequence of static definition...

Get the answers...

Today i will write about how i get all the user answers  and store them in users_answers table:


    protected void saveAnswers()
    {
       if (IsPostBack)
       {


           clsDataAccess myclass = new clsDataAccess();
           myclass.openConnection();


           SqlCommand selectCMD = new SqlCommand("SELECT user_id, user_name, question_id, answer_id, answer_text FROM users_answers", myclass.getConn());
           selectCMD.CommandTimeout = 30;

           SqlDataAdapter users_answersDA = new SqlDataAdapter();
           users_answersDA.SelectCommand = selectCMD;

           DataSet users_answersDS = new DataSet();
                                
           users_answersDA.TableMappings.Add("Table", "users_answers");
           users_answersDA.Fill(users_answersDS, "users_answers");
          
           myclass.closeConnection();


           string strUserID = Membership.GetUser(User.Identity.Name).ProviderUserKey.ToString();
           bool IsAnyAnswered = false;


           foreach (cQuestion oQuestion in Questions)
           {
               if (oQuestion.SaveAnswers(Request, users_answersDS.Tables["users_answers"], User.Identity.Name, strUserID))
                   IsAnyAnswered = true;

           }

         

           if (IsAnyAnswered)
           {


               MultiView1.ActiveViewIndex = 1;

           }
       }//end of save answers

I have put on the page the MultiView control to show the user the "Thank you"
After he had answered the questions





Download the soure link

Getting started with docker

It is very simple to get started usig docker. All you need to do-is download the docker desktop for your system Once you get docker syste...